Submission #773869

#TimeUsernameProblemLanguageResultExecution timeMemory
773869vjudge1Zagrade (COI20_zagrade)C++17
100 / 100
865 ms1100 KiB
 #include <bits/stdc++.h>
using namespace std;
#define sp " "
//#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 200005

int ask(int a, int b){
	cout<<"? "<<a<<sp<<b<<endl;
	int res;
	cin>>res;
	return res;
}


int32_t main(){
	//fileio();
	//fastio();

	int n, q;
	cin>>n>>q;


	vector<int> arr(n + 5, 0);
	map<int ,int> pos;
	int curr = 0, it = 2;
	stack<int> last;
	last.push(1);
	while(it <= n){
		if (last.empty())
		{
			last.push(it);
			it++;
			continue;
		}
		int res = ask(last.top(), it);
		if (res){
			arr[last.top()] = 1, arr[it] = -1;
			last.pop();
		}
		else last.push(it);
		it++;
	}
	
	int m = last.size();
	int tmp = m / 2;
	while(tmp > 0){
		arr[last.top()] = 1;
		last.pop();
		tmp--;
	}

	while(last.size()){
		arr[last.top()] = -1;
		last.pop();
	}
	cout<<"! ";
	for (int i = 1; i <= n; i++){
		cout<<((arr[i] == 1) ? '(' : ')');
	}
	cout<<endl;
	//cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}

Compilation message (stderr)

zagrade.cpp: In function 'int32_t main()':
zagrade.cpp:31:6: warning: unused variable 'curr' [-Wunused-variable]
   31 |  int curr = 0, it = 2;
      |      ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...