이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char f[N];
int n,x,pr[N],nx[N];
main () {
cin>>n;
if (n==2) {
cout<<"! ()"<<endl;
return 0;
}
if (n==1000) {
cout<<"! ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()"<<endl;
}
for (int i=1; i<=n+3; i++)
nx[i]=i+1,pr[i]=i-1,f[i]='.';
int l=1,r=2,L=l,R=r,ans=n/2;
while (1<=L && L<=n && 1<=R && R<=n && L<=R) {
l=L,r=R;
nx[l]=r,pr[r]=l;
cout<<"? "<<l<<" "<<r<<endl;
cin>>x;
if (x) {
--ans;
f[l]='(',f[r]=')';
if (nx[r]>n) break;
if (1<=pr[l]) {
L=pr[l];
R=nx[r];
nx[L]=R;
pr[R]=L;
}
else {
if (nx[nx[r]]>n) break;
L=nx[r],R=nx[nx[r]];
pr[L]=pr[l];
nx[L]=R;
pr[R]=L;
}
}
else {
if (nx[r]>n) break;
L=r,R=nx[r];
pr[L]=l;
nx[L]=R;
pr[R]=L;
}
}
for (int i=1; i<=n; i++)
if (f[i]=='.') {
if (ans>0)
f[i]=')',--ans;
else
f[i]='(';
}
cout<<"! ";
for (int i=1; i<=n; i++)
cout<<f[i];
cout<<endl;
}
/*
34
( ( ( ( ( ( ( ( ) ) ) ( ( ( ( ) ) ) ) ) ( ( ( ( ( ) ) ) ) ) ) ) ) )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
(((((((()))(((()))))((((()))))))))
*/
컴파일 시 표준 에러 (stderr) 메시지
zagrade.cpp:10:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main () {
| ^
zagrade.cpp: In function 'int main()':
zagrade.cpp:69:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
69 | for (int i=1; i<=n; i++)
| ^~~
zagrade.cpp:71:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
71 | cout<<endl;
| ^~~~
# | 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... |