Submission #640285

# Submission time Handle Problem Language Result Execution time Memory
640285 2022-09-14T05:49:31 Z makanhulia Zagrade (COI20_zagrade) C++17
0 / 100
0 ms 208 KB
#include <bits/stdc++.h>
using namespace std;

#define nyahalo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define otsumiko exit(0);
#define mikodanye priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > >
#define mikochi priority_queue<long long, vector<long long>, greater<long long> >

long long n, q, x, a[100069], pi, np, ng;
stack<long long> stk;

int main() {
  nyahalo
  long long i, j;
  cin >> n >> q;
  np = n/2;
  ng = n/2;
  for (i=1; i<=n; i++) {
    a[i] = 0;
  }
  if(q == n-1) {
    a[1] = 1;
    stk.push(1);
    for (i=2; i<=n; i++) {
      if (stk.empty()) {
        stk.push(i);
        a[i] = 1;
      } else {
        pi = stk.top();
        cout << "? " << pi << " " << i << "\n" << flush;
        cin >> x;
        if (x == 1) {
          a[i] = -1;
          stk.pop();
        } else {
          a[i] = 1;
          stk.push(i);
        }
      }
    }
    cout << "! ";
    for (i=1; i<=n; i++) {
      if (a[i] == 1) {
        cout << "(";
      } else {
        cout << ")";
      }
    }
    cout << "\n" << flush;
  }
  for (i=2; i<=n; i+=2) {
    for (j=1; j<=n-i+1; j++) {
      cout << "? " << j << " " << j+i-1 << "\n" << flush;;
      cin >> x;
      if (x == 1) {
        if (a[j] == 0) {
          np--;
        }
        a[j] = 1;
        if (a[j+i-1] == 0) {
          ng--;
        }
        a[j] = -1;
      }
    }
  }
  for (i=1; i<=n; i++) {
    if (a[i] == 0) {
      if (ng>0) {
        a[i] = -1;
        ng--;
      } else {
        a[i] = 1;
        np--;
      }
    }
  }
  cout << "! ";
  for (i=1; i<=n; i++) {
    if (a[i] == 1) {
      cout << "(";
    } else {
      cout << ")";
    }
  }
  cout << "\n";
  otsumiko
}
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -