Submission #968415

# Submission time Handle Problem Language Result Execution time Memory
968415 2024-04-23T11:58:08 Z Isam Superpozicija (COCI22_superpozicija) C++17
30 / 110
28 ms 4468 KB
#include<bits/stdc++.h>
using namespace std;

int n, l[100100], r[100100];

string z;

int ans[100100];

int gr[200200];

set<pair<int, int>> st;

signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int T;
	cin >> T;
	function<void()> test_case = [](){
		cin >> n >> z;
			
		st.clear();
		z = '.' + z;
		for(register int i = 1; i <= n; ++i){
			cin >> l[i] >> r[i];
			gr[l[i]] = r[i];
			gr[r[i]] = l[i];
			if(z[l[i]] == '(' && z[r[i]] == '('){
				ans[i] = 0;
				z[r[i]] = '.';
			}else if(z[l[i]] == ')' && z[r[i]] == ')'){
				ans[i] = 1;
				z[l[i]] = '.';
			}else if(z[l[i]] == '(' && z[r[i]] == ')'){
				st.insert({l[i], i});
				z[l[i]] = '.';
				ans[i] = 1;
			}else{ // ) (
				st.insert({r[i], i});
				z[r[i]] = '.';
				ans[i] = 0;
			}
			
			
		}
		
		if(n & 1) return cout << -1 << '\n', void();
		
		int tot(0);
		
		for(register int i = 1; i <= n * 2; ++i){
			
			if(z[i] != '.') tot += (z[i]=='('?1:-1);
			
			while(tot < 0 && !st.empty()){
				
			//	if(st.empty()) return cout << -1 << '\n', void();
				
				auto it = st.begin();
				
				int pos = it->first, j = it->second;
				
				
				
				if(pos > i) break; //return cout << -1 << '\n', void();
				
				++tot;
				
				z[pos] = '(';
				
				
				if(gr[pos] <= i) ++tot;
				
				z[gr[pos]] = '.';
				
				ans[j] ^= 1;
				
				st.erase(it);
				
				
				
			}
			
			
		}
		
	//	cerr<<"gnrem"<<endl;
		
		while(tot < 0){
				
				if(st.empty()) return cout << -1 << '\n', void();
				
				auto it = st.begin();
				
				int pos = it->first, j = it->second;
				
				++tot;
				
				z[pos] = '(';
				
				ans[j] ^= 1;
				
				++tot;
				
				z[gr[pos]] = '.';
				
				
				
				st.erase(it);
				
				
				
			}
		
		
		
		
		
		
		
		function<bool(const string)> is_valid = [](const string &s){
			int tot(0);
			for(register int i = 0; i < (int)s.size(); ++i){
				tot += (s[i]=='('?1:-1);
				if(tot < 0) return false;
			}
			return !tot;
		};
		
				
		string tmp = "";
		
		for(register int i = 1; i <= 2*n; ++i){
			if(z[i] == '.') continue;
			tmp += z[i];
		}
		
		if(is_valid(tmp)){
			for(register int i = 1; i <= n; ++i) cout << ans[i] << ' ';
		}else{
			cout << -1;
		}
		
		cout << '\n';
		
	};
	while(T--) test_case();
	return 0;
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:23:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   23 |   for(register int i = 1; i <= n; ++i){
      |                    ^
Main.cpp:50:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |   for(register int i = 1; i <= n * 2; ++i){
      |                    ^
Main.cpp: In lambda function:
Main.cpp:122:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  122 |    for(register int i = 0; i < (int)s.size(); ++i){
      |                     ^
Main.cpp: In lambda function:
Main.cpp:132:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  132 |   for(register int i = 1; i <= 2*n; ++i){
      |                    ^
Main.cpp:138:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  138 |    for(register int i = 1; i <= n; ++i) cout << ans[i] << ' ';
      |                     ^
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 344 KB Output is correct
2 Correct 13 ms 604 KB Output is correct
3 Correct 12 ms 972 KB Output is correct
4 Correct 13 ms 1116 KB Output is correct
5 Correct 12 ms 1368 KB Output is correct
6 Correct 8 ms 1660 KB Output is correct
7 Correct 10 ms 1860 KB Output is correct
8 Correct 12 ms 2048 KB Output is correct
9 Correct 13 ms 2116 KB Output is correct
10 Correct 14 ms 2356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 28 ms 584 KB Output is correct
3 Correct 20 ms 860 KB Output is correct
4 Correct 18 ms 1368 KB Output is correct
5 Correct 24 ms 1900 KB Output is correct
6 Correct 20 ms 2392 KB Output is correct
7 Correct 11 ms 2644 KB Output is correct
8 Correct 19 ms 3160 KB Output is correct
9 Correct 16 ms 3420 KB Output is correct
10 Correct 22 ms 4168 KB Output is correct
11 Correct 26 ms 4468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -