#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, q;
char c[MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
stack <int> s;
for(int i = n; i >= 1; i--)
{
if(s.empty())
{
s.push(i);
}
else
{
cout << "? " << i << ' ' << s.top() << endl;
int id;
cin >> id;
if(id == 1)
{
c[i] = '(';
c[s.top()] = ')';
s.pop();
}
else
{
s.push(i);
}
}
}
int tmp = s.size() / 2;
for(int i = 1; i <= tmp; i++)
{
c[s.top()] = ')';
s.pop();
}
for(int i = 1; i <= tmp; i++)
{
c[s.top()] = '(';
s.pop();
}
cout << "! ";
for(int i = 1; i <= n; i++)
{
cout << c[i];
}
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
6 ms |
200 KB |
Output is correct |
3 |
Correct |
11 ms |
200 KB |
Output is correct |
4 |
Correct |
11 ms |
200 KB |
Output is correct |
5 |
Correct |
13 ms |
200 KB |
Output is correct |
6 |
Correct |
9 ms |
200 KB |
Output is correct |
7 |
Correct |
12 ms |
200 KB |
Output is correct |
8 |
Correct |
11 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
12 ms |
200 KB |
Output is correct |
3 |
Correct |
10 ms |
200 KB |
Output is correct |
4 |
Correct |
10 ms |
320 KB |
Output is correct |
5 |
Correct |
12 ms |
200 KB |
Output is correct |
6 |
Correct |
13 ms |
320 KB |
Output is correct |
7 |
Correct |
10 ms |
200 KB |
Output is correct |
8 |
Correct |
12 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
449 ms |
516 KB |
Output is correct |
3 |
Correct |
794 ms |
592 KB |
Output is correct |
4 |
Correct |
965 ms |
456 KB |
Output is correct |
5 |
Correct |
744 ms |
424 KB |
Output is correct |
6 |
Correct |
876 ms |
492 KB |
Output is correct |
7 |
Correct |
743 ms |
732 KB |
Output is correct |
8 |
Correct |
836 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
945 ms |
984 KB |
Output is correct |
3 |
Correct |
898 ms |
488 KB |
Output is correct |
4 |
Correct |
769 ms |
624 KB |
Output is correct |
5 |
Correct |
934 ms |
472 KB |
Output is correct |
6 |
Correct |
1091 ms |
700 KB |
Output is correct |
7 |
Correct |
1125 ms |
520 KB |
Output is correct |
8 |
Correct |
946 ms |
476 KB |
Output is correct |