답안 #968363

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

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

string z;

int ans[100002];

int gr[100002];

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;
			}
			
			
		}
		
		int tot(0);
		
		for(register int i = 1; i <= 2*n; ++i){
			
			if(z[i] ^ '.') tot += (z[i]=='('?1:-1);
			
			while(tot < 0 && !st.empty()){
				
				int pos = st.begin()->first, j = st.begin()->second;
					
				ans[j] ^= 1;
					
				z[pos] = '(';
					
				z[gr[pos]] = '.';
					
				tot += 2;
					
				st.erase(st.begin());
				
				
			}
			
			
		}
		
		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:22:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   22 |   for(register int i = 1; i <= n; ++i){
      |                    ^
Main.cpp:47:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |   for(register int i = 1; i <= 2*n; ++i){
      |                    ^
Main.cpp: In lambda function:
Main.cpp:73:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   73 |    for(register int i = 0; i < (int)s.size(); ++i){
      |                     ^
Main.cpp: In lambda function:
Main.cpp:83:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   83 |   for(register int i = 1; i <= 2*n; ++i){
      |                    ^
Main.cpp:89:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   89 |    for(register int i = 1; i <= n; ++i) cout << ans[i] << ' ';
      |                     ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1372 KB Output is correct
2 Correct 14 ms 1880 KB Output is correct
3 Correct 12 ms 1852 KB Output is correct
4 Correct 14 ms 2396 KB Output is correct
5 Correct 13 ms 2392 KB Output is correct
6 Correct 9 ms 2340 KB Output is correct
7 Correct 10 ms 2600 KB Output is correct
8 Correct 12 ms 2908 KB Output is correct
9 Correct 14 ms 3144 KB Output is correct
10 Correct 16 ms 3384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 18 ms 1372 KB Output is correct
3 Correct 19 ms 2140 KB Output is correct
4 Correct 19 ms 2396 KB Output is correct
5 Correct 21 ms 2904 KB Output is correct
6 Correct 21 ms 3420 KB Output is correct
7 Correct 11 ms 3160 KB Output is correct
8 Incorrect 16 ms 3928 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -