Submission #320393

#TimeUsernameProblemLanguageResultExecution timeMemory
320393phathnvZagrade (COI20_zagrade)C++11
100 / 100
996 ms1008 KiB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "Zagrade"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 1e5 + 1;

int n, q;
char res[N];
stack <int> s;

bool ask(int l, int r){
    cout << "? " << l << ' ' << r << endl << flush;
    int res;
    cin >> res;
    return res;
}

int main(){
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        if (s.empty()){
            s.push(i);
            continue;
        }
        if (ask(s.top(), i)){
            res[s.top()] = '(';
            res[i] = ')';
            s.pop();
        } else {
            s.push(i);
        }
    }
    int sz = s.size();
    for(int i = 1; i <= sz / 2; i++){
        res[s.top()] = '(';
        s.pop();
    }
    for(int i = 1; i <= sz / 2; i++){
        res[s.top()] = ')';
        s.pop();
    }
    cout << "! " << string(res + 1, res + 1 + n) << endl << flush;
    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...