답안 #968473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968473 2024-04-23T12:57:28 Z Isam Superpozicija (COCI22_superpozicija) C++17
10 / 110
24 ms 3892 KB
#include<bits/stdc++.h>
using namespace std;

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

string z;

int ans[100100];

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(v.begin(), v.end());
		
		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:42:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   42 |   for(register int i = 1; i <= n; ++i){
      |                    ^
Main.cpp:120:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  120 |   for(register int i = 1; i <= n; ++i){
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 348 KB Output is correct
2 Correct 19 ms 908 KB Output is correct
3 Correct 17 ms 1112 KB Output is correct
4 Correct 21 ms 1628 KB Output is correct
5 Correct 19 ms 1880 KB Output is correct
6 Correct 12 ms 2392 KB Output is correct
7 Correct 16 ms 2664 KB Output is correct
8 Correct 18 ms 3164 KB Output is correct
9 Correct 22 ms 3516 KB Output is correct
10 Correct 24 ms 3892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -