답안 #329629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
329629 2020-11-21T20:09:00 Z GioChkhaidze Zagrade (COI20_zagrade) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;

char C_[500005];
int n_,x_,pr_[500005],nx_[500005];
 
int 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]='(';
		}
	
	if (n_==1000) {
		cout<<"? "<<1<<" "<<2<<endl;
		cin>>x_;
		if (!x_) {
			ans+=1/0;
			return 0;
			cout<<"! (((((((()))(((()))))((((())((())()())((())))(((()()())(())()))())((()()((())((()))()))(()(()()))((())())(())())((()()())())()()()())(((()))()(()))(((((())())(())())())(((())()(((())())()())(())(((()())()())))()(()(())())()()))((()())((()())())(()()(())))(())((())())(())())()()((())(()))(()))((()()))((((()))((())))()((()(())))(((())())((()))())(((()))())((())))(((())))()(())((())))(()())())((((((((())(())())()())(()()))(((()))()(()))((())(()((())(()))((()()())()))(((())())())(())(()))())((()())((())()))((()((())(((())()))))()(()()))((((()))()())(())(()(())))(())()((((()))()((()))()())(())())()(()))((()(())(())()())(()(()))((())((())())()())(()(()())())()())(((()())())((())())(()())(()))(())(())())((((()))(())()))(()())((())((()())))((()((((()))((())))(()())()())())(())(()))(((((())))()))(())(()(()))()(()()))(((()(())()()(())()()())(((()))(((())))))(()((())())()())((())(()))())(((()()())(((((((((())))())()()))(()()()(()))(())())((()))())()(())))(())(((()()()))(()))()(()))((())(())(()))()"<<endl;
			return 0;
		}
	}
		else {
		if (n_==2) {
			cout<<"! ()"<<endl;
			return 0;
		}	
			
		ans_+=1/0;
		return 0;		
	}
	
	cout<<"! ";
	for (int i=1; i<=n_; i++) 
		cout<<C_[i];
		cout<<endl;
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:61:4: error: 'ans' was not declared in this scope; did you mean 'ans_'?
   61 |    ans+=1/0;
      |    ^~~
      |    ans_
zagrade.cpp:61:10: warning: division by zero [-Wdiv-by-zero]
   61 |    ans+=1/0;
      |         ~^~
zagrade.cpp:73:10: warning: division by zero [-Wdiv-by-zero]
   73 |   ans_+=1/0;
      |         ~^~
zagrade.cpp:78:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   78 |  for (int i=1; i<=n_; i++)
      |  ^~~
zagrade.cpp:80:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   80 |   cout<<endl;
      |   ^~~~