제출 #679927

#제출 시각아이디문제언어결과실행 시간메모리
679927CyanmondZagrade (COI20_zagrade)C++17
71 / 100
864 ms588 KiB
#include <bits/stdc++.h>

bool query(int l, int r) {
    std::cout << '?' << ' ' << l + 1 << ' ' << r << std::endl;
    int res;
    std::cin >> res;
    return res == 1;
}

void answer(std::string s) {
    std::cout << '!' << ' ' << s << std::endl;
    std::exit(0);
}

int main() {
    int N, Q;
    std::cin >> N >> Q;

    // valid sequence
    std::stack<int> stk;
    std::string ans(N, '0');
    int l = 0;
    for (int i = 1; i < N; ++i) {
        const int r = i + 1;
        const auto res = query(l, r);
        if (res) {
            ans[l] = '(';
            ans[i] = ')';
            if (stk.empty()) {
                l = i + 1;
                ++i;
            } else {
                l = stk.top();
                stk.pop();
            }
        } else {
            stk.push(l);
            l = i;
        }
    }
    answer(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...