Submission #381333

#TimeUsernameProblemLanguageResultExecution timeMemory
381333NONAMEZagrade (COI20_zagrade)C++17
100 / 100
982 ms1376 KiB
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline bool chmin(T& a, const T b) {a = min(a, b); return (a == b);} template <typename T> inline bool chmax(T& a, const T b) {a = max(a, b); return (a == b);} int n, q; string s; vector <int> vc; inline void cls() {} int ask(int x, int y) { cout << "? " << (x + 1) << " " << (y + 1) << endl; cin >> x; return x; } void solve() { cls(); cin >> n >> q; for (int i = 0; i < n; ++i) { s += '?'; } for (int i = 0; i < n; ++i) { if (vc.empty()) { vc.push_back(i); } else { int x = ask(vc.back(), i); if (x) { s[vc.back()] = '('; s[i] = ')'; vc.pop_back(); } else { vc.push_back(i); } } } int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (s[i] == '?'); } assert(!(cnt & 1)); int cl = (cnt >> 1); for (int i = 0; i < n; ++i) { if (s[i] == '?') { if (cl) { --cl; s[i] = ')'; } else { s[i] = '('; } } } cout << "! " << s << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // int t = 1; #ifdef _LOCAL system("color a"); // freopen("in.txt", "r", stdin); // cin >> t; #endif // for (int i = 1; i <= t; ++i) { // cerr << "Case #" << i << ": \n"; solve(); // cerr << "\n"; // } 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...