제출 #781274

#제출 시각아이디문제언어결과실행 시간메모리
781274christinelynnZagrade (COI20_zagrade)C++17
71 / 100
719 ms808 KiB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int,int>
#define fr first
#define sc second
#define query(l, r) cout << "? " << l << " " << r << endl; cin >> res;
using namespace std;

const int N = 1e5+5;

string ans; bool res;

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
    int n, q; cin >> n >> q;
    ans.assign(n, ' ');
    stack<int> s;
    s.push(1);
    for (int i = 2; i <= n; i++) {
    if (s.empty()) {
      s.push(i);
      continue;
    }
        int cur = s.top();
        query(cur, i);
        if (res) {
            ans[cur-1] = '(';
            ans[i-1] = ')';
            s.pop();
        } else s.push(i);
    }
    cout << "! " << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...