답안 #329601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
329601 2020-11-21T19:08:03 Z GioChkhaidze Zagrade (COI20_zagrade) C++14
0 / 100
4 ms 364 KB
#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;	
	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;
		if (L==R) {
			ans+=1/0;
			return 0;
		}
		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 {
				L=nx[r],R=nx[nx[r]];
				pr[L]=pr[l];
			}
		}
			else {
				L=r,R=nx[r];
				pr[r]=l;
				pr[nx[r]]=r;
			}
	}
	
	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;
}

Compilation message

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:19:10: warning: division by zero [-Wdiv-by-zero]
   19 |    ans+=1/0;
      |         ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Incorrect 4 ms 364 KB Mismatch at position 2. Expected (, found )
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Mismatch at position 2. Expected (, found )
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 364 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -