Submission #1003839

#TimeUsernameProblemLanguageResultExecution timeMemory
1003839vjudge1Zagrade (COI20_zagrade)C++17
71 / 100
598 ms596 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; function<bool (int, int)> query = [](int l, int r) { cout << "? " << l + 1 << " " << r + 1 << endl; int x; cin >> x; return x; }; string s(n, '0'); stack<pair<int, int>> inters; int cnt = 0; for (int i = 0; i < n-1; ++i) { if (query(i, i + 1)) { s[i] = '('; s[i+1] = ')'; ++cnt; int l = i, r = i + 1; while (true) { if (!inters.empty()) { auto [l1, r1] = inters.top(); if (r1 == l - 1) { l = l1; inters.pop(); } } if (l > 0 && r < n - 1 && query(l - 1, r + 1)) { --l; ++r; s[l] = '('; s[r] = ')'; ++cnt; } else break; } inters.emplace(l, r); i = r; } } int falta = n - cnt; for (char &c: s) if (c == '0') if (falta > 0) { c = ')'; -- falta; } else c = '('; cout << "! " << s << "\n"; }

Compilation message (stderr)

zagrade.cpp: In function 'int main()':
zagrade.cpp:48:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   48 |   if (c == '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...