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;
#define sp " "
//#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 200005
int ask(int a, int b){
cout<<"? "<<a<<sp<<b<<endl;
int res;
cin>>res;
return res;
}
int32_t main(){
//fileio();
//fastio();
int n, q;
cin>>n>>q;
vector<int> arr(n + 5, 0);
map<int ,int> pos;
int curr = 0, it = 2;
stack<int> last;
last.push(1);
while(it <= n){
if (last.empty())
{
last.push(it);
it++;
continue;
}
int res = ask(last.top(), it);
if (res){
arr[last.top()] = 1, arr[it] = -1;
last.pop();
}
else last.push(it);
it++;
}
int m = last.size();
int tmp = m / 2;
while(tmp > 0){
arr[last.top()] = 1;
last.pop();
tmp--;
}
while(last.size()){
arr[last.top()] = -1;
last.pop();
}
cout<<"! ";
for (int i = 1; i <= n; i++){
cout<<((arr[i] == 1) ? '(' : ')');
}
cout<<endl;
//cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
Compilation message (stderr)
zagrade.cpp: In function 'int32_t main()':
zagrade.cpp:31:6: warning: unused variable 'curr' [-Wunused-variable]
31 | int curr = 0, it = 2;
| ^~~~
# | 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... |