Submission #1003936

# Submission time Handle Problem Language Result Execution time Memory
1003936 2024-06-20T20:21:01 Z vjudge1 Zagrade (COI20_zagrade) C++17
71 / 100
574 ms 1672 KB
#include <bits/stdc++.h>

using namespace std;

int marc[100005];
stack<int> st;

int main(){
	int n,q; cin>>n>>q;
	cout<<"? "<<1<<" "<<n<<" "<<endl;
	int y; cin>>y;
	if(y == 1){
		marc[n] = 0;
		for(int i = 1; i < n; i++){
			if(st.size() == 0){
				marc[i] = 1;
				st.push(i);
				continue;
			}
			cout<<"? "<<st.top()<<" "<<i<<endl;
			int x; cin>>x;
			if(x == 0){
				marc[i] = 1;
				st.push(i);
			}else{
				marc[i] = 0;
				st.pop();
			}
		}
		cout<<"! ";
		for(int i = 1; i <= n; i++){
			if(marc[i] == 0)cout<<")";
			else cout<<"(";
		}cout<<endl;
		return 0;
	}

	else{
		for(int i = 1; i <= n; i++)marc[i] = -1;
		marc[n] = 1; int qtd = 0;
		for(int i = 1; i < n; i++){
			if(st.size() == 0){
				st.push(i);
				continue;
			}
			cout<<"? "<<st.top()<<" "<<i<<endl;
			int x; cin>>x;
			if(x == 1){
				qtd++;
				marc[st.top()] = 1;
				marc[i] = 0;
				st.pop();
			}else{
				st.push(i);
			}
		}

		for(int i = 1; i <= n; i++)
			if(marc[i] == -1){
				if(qtd < n/2){marc[i] = 0; qtd++;}
				else marc[i] = 1;
			}

		cout<<"! ";
		for(int i = 1; i <= n; i++){
			if(marc[i] == 0)cout<<")";
			else cout<<"(";
		}cout<<endl;
		return 0;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 412 KB Output is correct
3 Incorrect 4 ms 344 KB Mismatch at position 511. Expected (, found )
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 263 ms 1100 KB Output is correct
3 Correct 551 ms 1584 KB Output is correct
4 Correct 574 ms 1464 KB Output is correct
5 Correct 556 ms 1532 KB Output is correct
6 Correct 564 ms 1428 KB Output is correct
7 Correct 555 ms 1216 KB Output is correct
8 Correct 558 ms 1184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 543 ms 1672 KB Output is correct
3 Incorrect 552 ms 1612 KB Mismatch at position 49727. Expected (, found )
4 Halted 0 ms 0 KB -