Submission #329619

# Submission time Handle Problem Language Result Execution time Memory
329619 2020-11-21T19:46:39 Z GioChkhaidze Zagrade (COI20_zagrade) C++14
0 / 100
5 ms 364 KB
#include <bits/stdc++.h>
 
using namespace std;

char C[100005];
int n,x,pr[100005],nx[100005];
 
int32_t main () {
	cin>>n;

	for (int i=1; i<=n+3; i++) 
		nx[i]=i+1,pr[i]=i-1,C[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;
			C[l]='(',C[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 (C[i]=='.') {			
			if (ans>0) 
				C[i]=')',--ans;
					else 
				C[i]='(';
		}
	
	cout<<"! ";
	for (int i=1; i<=n; i++) 
		cout<<C[i];
		cout<<endl;
}

Compilation message

zagrade.cpp: In function 'int32_t main()':
zagrade.cpp:58:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   58 |  for (int i=1; i<=n; i++)
      |  ^~~
zagrade.cpp:60:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   60 |   cout<<endl;
      |   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 3 ms 364 KB Output is correct
3 Incorrect 5 ms 364 KB Mismatch at position 2. Expected (, found )
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Mismatch at position 2. Expected (, found )
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -