Submission #1152518

#TimeUsernameProblemLanguageResultExecution timeMemory
1152518yhkhooZagrade (COI20_zagrade)C++20
100 / 100
244 ms920 KiB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
#define fi first
#define se second

int main(){
    cin.tie(0); ios_base::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    char ans[n];
    memset(ans, '?', sizeof(ans));
    int p[n];
    memset(p, -1, sizeof(p));
    int s=0;
    for(int e=1; e<n; e++){
        cout << '?' << ' ' << s+1 << ' ' << e+1 << endl;
        bool temp;
        cin >> temp;
        if(temp){
            assert(ans[s] == '?');
            assert(ans[e] == '?');
            ans[s] = '(';
            ans[e] = ')';
            if(s == 0){ // cannot expand further, bounded by edge
                s = e;
                continue;
            }
            if(p[s-1] != -1){ // expand from prev bracketex
                p[e] = p[s-1];
                s = p[s-1]-1;
            }
            else{ // expand from cur bracketex
                p[e] = s;
                s = s-1;
            }
        }
        else{
            s = e;
        }
    }
    int qc = 0;
    int tqc = 0;
    for(int i=0; i<n; i++){
        if(ans[i] == '?'){
            tqc++;
        }
    }
    cout << '!' << ' ';
    for(int i=0; i<n; i++){
        if(ans[i] == '?'){
            qc++;
            if(qc > tqc/2){
                ans[i] = '(';
            }
            else{
                ans[i] = ')';
            }
        }
        cout << ans[i];
    }
    cout << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...