답안 #1106815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106815 2024-10-31T05:37:36 Z 0pt1mus23 Zagrade (COI20_zagrade) C++14
0 / 100
4 ms 504 KB
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
#define int long long int
#define ins insert      
#define pb push_back
// #define endl '\n'
#define putr(x) cout<<x<<endl;return; 
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 5e5 +5, inf = INT_MAX, LL = 30;

int ask(int l,int r){
    cout<<"? "<<l<<" "<<r<<endl;
    int x;cin>>x;
    return x;
}

void rush(){
    int n;
    cin>>n;
    vector<char> ans(n+10,'_');
    stack<int> st;
    for(int i=1;i<=n;i++){
        if(st.empty()){
            st.push(i);
        }
        else{
            int x = st.top();
            if(ask(x,i)){
                ans[x]='(';
                ans[i]=')';
                st.pop();
            }
            else{
                st.push(i);
            }
        }
    }
    int qal =0;
    for(int i=1;i<=n;i++){
        if(ans[i]=='_'){
            qal++;
        }
    }
    qal/=2;
    for(int i = n;i>=1;i--){
        if(ans[i]=='_'){
            if(qal){
                qal--;
                ans[i]='(';
            }
            else{
                ans[i]=')';
            }
        }
    }
    string res="";
    for(int i=1;i<=n;i++) res+=ans[i];
    cout<<"! "<<res<<endl;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int tt = 1; 
    // cin>>tt;

    while(tt--){
        rush();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Incorrect 4 ms 336 KB Mismatch at position 2. Expected (, found )
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Mismatch at position 2. Expected (, found )
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 504 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -