Submission #1003949

# Submission time Handle Problem Language Result Execution time Memory
1003949 2024-06-20T20:44:39 Z vjudge1 Zagrade (COI20_zagrade) C++17
71 / 100
618 ms 1592 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;
		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 3 ms 344 KB Output is correct
3 Correct 5 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 249 ms 1036 KB Output is correct
3 Correct 551 ms 1092 KB Output is correct
4 Correct 540 ms 1212 KB Output is correct
5 Correct 516 ms 1444 KB Output is correct
6 Correct 618 ms 1592 KB Output is correct
7 Correct 566 ms 1268 KB Output is correct
8 Correct 530 ms 1248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -