제출 #1152464

#제출 시각아이디문제언어결과실행 시간메모리
1152464simuyuZagrade (COI20_zagrade)C++20
0 / 100
460 ms652 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

ll N, Q;
string res;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> Q;

    for (ll i=0; i<N; i++) {
        res += "?";
    }


    ll left, right;

    int resp;
    for (ll sz=2; sz<=N; sz+=2) {
        ll startpt=0;
        while (startpt<=N-sz) {
            cout << "? " << startpt+1 << ' ' << startpt+sz << endl; // this is in their coordinates not ours
            cin >> resp;
            if (resp) {
                // is valid --> pattern known
                // from startpt to startpt+sz (inclusive, exclusive) is a "block"
                left = startpt;
                right = startpt+sz;
                try {

                    while (right > left) {
                        while (res[right-1] != '?') {
                            right -= 2;
                            if (right<=left) break;
                        }
                        while (res[left] != '?') {
                            left += 2;
                            if (right<=left) break;
                        }

                        if (right <= left) break;

                        /*cout << "LEFT: " << left << ", RIGHT: " << right << "; ";
                        for (int i=left; i<right; i++) {
                            cout << res[i];
                        }
                        cout << endl;*/

                        // now the first and last are '(' and ')'
                        res[left] = '(';
                        res[right-1] = ')';
                        left++;
                        right--;
                    }
                } catch (exception) {
                    ll i=0;
                    while (true) {
                        i++;
                    }
                }
                // set already yay

                startpt += sz;
                continue;
            }

            startpt++;
        }
    }

    cout << "! " << res << 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...