제출 #948364

#제출 시각아이디문제언어결과실행 시간메모리
948364NeroZeinZagrade (COI20_zagrade)C++17
100 / 100
547 ms2060 KiB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

bool ask(int l, int r) {
  cout << "?" << ' ' << l << ' ' << r << endl; 
  bool ret;
  cin >> ret;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> stk; 
  vector<char> ans(n + 1); 
  for (int r = 1; r <= n; ++r) {
    if (stk.empty()) {
      stk.push_back(r);
      continue; 
    }
    int l = stk.back();
    bool valid = ask(l, r);
    if (valid) {
      ans[l] = '(';
      ans[r] = ')';
      stk.pop_back();
    } else {
      stk.push_back(r); 
    }
  }
  int m = (int) stk.size();
  for (int i = 0; i < m / 2; ++i) {
    ans[stk[i]] = ')';
  }
  for (int i = m / 2; i < m; ++i) {
    ans[stk[i]] = '(';
  }
  cout << "! ";
  for (int i = 1; i <= n; ++i) {
    cout << ans[i];
  }
  cout << 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...