#include <bits/stdc++.h>
using namespace std;
int query(int a, int b)
{
cout << "? " << a << " " << b << endl;
int resp; cin >> resp;
return resp;
}
void solve(int N, int Q)
{
string resp(N, '.'), resto;
for (int i = 1; i <= N; i++)
{
if (resto.empty()) resto.push_back(i);
else if(query(resto.back(), i))
{
resp[resto.back()-1] = '(';
resp[i-1] = ')';
resto.pop_back();
}
else resto.push_back(i);
}
// cerr << "resp: " << resp << '\n';
// cerr << "resto: "; for (auto x : resto) cerr << " "; cerr << '\n';
int sz = resto.size();
for (int i = 0; i < sz/2; i++) resp[resto[i]-1] = ')';
for (int i = sz/2; i < sz; i++) resp[resto[i]-1] = '(';
cout << "! " << resp << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, Q;
cin >> N >> Q;
solve(N, Q);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
452 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |