Submission #968472

# Submission time Handle Problem Language Result Execution time Memory
968472 2024-04-23T12:55:43 Z Isam Superpozicija (COCI22_superpozicija) C++17
10 / 110
34 ms 4148 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>> pq;

set<int> st;

vector<int> tmp;

vector<pair<int, int>> v;

inline bool makni(int pos){
	
	auto it = st.lower_bound(pos);
	
	if(it == st.end()) return 0;
	
	st.erase(it);
	
	return 1;
	
}


signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int T;
	cin >> T;
	function<void()> test_case = [](){
		cin >> n >> z;
		
		z = '.' + z;
		
		st.clear(), pq.clear(), v.clear(), tmp.clear();
		
		for(register int i = 1; i <= n; ++i){
			cin >> l[i] >> r[i];
			
			if(z[l[i]] == '(' && z[r[i]] == '('){
				tmp.emplace_back(l[i]);
				
				ans[i] = 0;
				
				
			}else if(z[l[i]] == ')' && z[r[i]] == ')'){
				st.insert(r[i]);
				
				ans[i] = 1;
				
			}else if(z[l[i]] == '(' && z[r[i]] == ')'){
				st.insert(r[i]);
				
				v.emplace_back(pair<int, int>{l[i], i});
				
				ans[i] = 1;
				
			}else{
				
				st.insert(l[i]);
				
				v.emplace_back(pair<int, int>{l[i], i});
				
				ans[l[i]] = 0;
				
			}
			
			
			
			
		}
		
		if(n & 1) return cout << -1 << '\n', void();
		
		for(auto to : tmp){
			
			if(!makni(to)) return cout << -1 << '\n', void();
			
			
		}
		
		
		sort(l+1, l+n+1);
		
		int p = -1;
		
		while(!st.empty()){
			int lim = *st.begin();
			
			while(p + 1 < (int)v.size() && v[p+1].first <= lim){
				p++;
				
				int ind = v[p].second;
				
				pq.insert({r[ind], ind});
				
			}
			
			if(pq.empty()) return cout << -1 << '\n', void();
			
			int ind = pq.begin()->second;
			
			pq.erase(pq.begin());
			
			ans[ind] ^= 1;
			
			if(!makni(l[ind])) return cout << -1 << '\n', void();
			
			if(!makni(r[ind])) return cout << -1 << '\n', void();
			
			
		}
		

		for(register int i = 1; i <= n; ++i){
			 cout << ans[i] << " \n"[i==n];
		}
		
		
		
		
		
	};
	while(T--) test_case();
	return 0;
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:44:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |   for(register int i = 1; i <= n; ++i){
      |                    ^
Main.cpp:122:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  122 |   for(register int i = 1; i <= n; ++i){
      |                    ^
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 500 KB Output is correct
2 Correct 22 ms 860 KB Output is correct
3 Correct 19 ms 1112 KB Output is correct
4 Correct 26 ms 1628 KB Output is correct
5 Correct 21 ms 1880 KB Output is correct
6 Correct 13 ms 2240 KB Output is correct
7 Correct 20 ms 2596 KB Output is correct
8 Correct 18 ms 3164 KB Output is correct
9 Correct 26 ms 3632 KB Output is correct
10 Correct 34 ms 4148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -