답안 #780922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780922 2023-07-12T14:40:20 Z christinelynn Zagrade (COI20_zagrade) C++17
100 / 100
757 ms 860 KB
#include<bits/stdc++.h>
using namespace std;
bool ask(int l, int r) {
  if((r-l)&1^1) return 0;
  cout << "? " << l << ' ' << r << endl;
  bool ret; cin >> ret;
  return ret;
}
int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, q; cin >> n >> q;
  stack<int> J;
  string s;
  for(int i=0; i<n; i++) s+='-';
  for(int i=0; i<n; i++) {
    if(J.empty()) J.push(i);
    else {
      if(ask(J.top()+1, i+1)) s[J.top()]='(', s[i]=')', J.pop();
      else J.push(i);
    }
  }
  int sz=(int)J.size() >> 1;
  while(!J.empty()) {
    if(sz) s[J.top()]='(', sz--;
    else s[J.top()]=')';
    J.pop();
  }
  cout << "! " << s << '\n';
  return 0;
}

Compilation message

zagrade.cpp: In function 'bool ask(int, int)':
zagrade.cpp:4:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    4 |   if((r-l)&1^1) return 0;
      |      ~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 5 ms 208 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 7 ms 284 KB Output is correct
5 Correct 4 ms 208 KB Output is correct
6 Correct 7 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 6 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 8 ms 320 KB Output is correct
3 Correct 7 ms 208 KB Output is correct
4 Correct 8 ms 316 KB Output is correct
5 Correct 8 ms 208 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 7 ms 220 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 340 ms 524 KB Output is correct
3 Correct 627 ms 520 KB Output is correct
4 Correct 608 ms 524 KB Output is correct
5 Correct 558 ms 524 KB Output is correct
6 Correct 632 ms 520 KB Output is correct
7 Correct 653 ms 684 KB Output is correct
8 Correct 629 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 726 ms 860 KB Output is correct
3 Correct 693 ms 520 KB Output is correct
4 Correct 690 ms 696 KB Output is correct
5 Correct 624 ms 524 KB Output is correct
6 Correct 670 ms 664 KB Output is correct
7 Correct 757 ms 652 KB Output is correct
8 Correct 702 ms 516 KB Output is correct