이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "Zagrade"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 1e5 + 1;
int n, q;
char res[N];
stack <int> s;
bool ask(int l, int r){
cout << "? " << l << ' ' << r << endl << flush;
int res;
cin >> res;
return res;
}
int main(){
cin >> n >> q;
for(int i = 1; i <= n; i++){
if (s.empty()){
s.push(i);
continue;
}
if (ask(s.top(), i)){
res[s.top()] = '(';
res[i] = ')';
s.pop();
} else {
s.push(i);
}
}
int sz = s.size();
for(int i = 1; i <= sz / 2; i++){
res[s.top()] = '(';
s.pop();
}
for(int i = 1; i <= sz / 2; i++){
res[s.top()] = ')';
s.pop();
}
cout << "! " << string(res + 1, res + 1 + n) << endl << flush;
return 0;
}
# | 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... |