Submission #679936

#TimeUsernameProblemLanguageResultExecution timeMemory
679936CyanmondZagrade (COI20_zagrade)C++17
100 / 100
847 ms952 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; 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; } } const int count_zero = std::count(ans.begin(), ans.end(), '0'); int c = 0; for (int i = 0; i < N; ++i) { if (ans[i] == '0') { ans[i] = c < count_zero / 2 ? ')' : '('; ++c; } } 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...