This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int ukr = 1e5+10;
ll n, m, id, a, b;
char ar[ukr];
vector<int> v;
int ask(int a, int b){
cout << "? " << a << " " << b << endl;
int kkl;
cin >> kkl;
return kkl;
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= n; i++){
ar[i] = '.';
}
ll pke = 0;
for(int i = 1; i <= n; i++){
if(v.empty()){
v.push_back(i);
}else{
if(ask(v.back(), i)){
ar[v.back()] = '(';
ar[i] = ')';
v.pop_back();
pke += 2;
}else{
v.push_back(i);
}
}
}
pke = n-pke;
pke/=2;
cout << "! ";
for(int i = 1; i <= n; i++){
if(ar[i] == '.'){
if(!pke){
ar[i] = '(';
}else{
pke--;
ar[i] = ')';
}
}
cout << ar[i];
}
cout << endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |