Submission #967823

# Submission time Handle Problem Language Result Execution time Memory
967823 2024-04-23T00:51:50 Z Isam Superpozicija (COCI22_superpozicija) C++17
0 / 110
13 ms 348 KB
#include<bits/stdc++.h>
using namespace std;

int n, a[100002], b[100002];
string z;

bool was[100002];

inline bool is_valid(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 == 0;
}


signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int T;
	cin >> T;
	function<void()> test_case = [](){
		cin >> n >> z;
		
		int openings(0), closings(0);
		
		for(register int i = 1; i <= n; ++i){
			cin >> a[i] >> b[i];
			a[i]--, b[i]--;
			
			openings += (z[a[i]] == '(');
		}
		
	//	if(openings != n) return cout << -1 << '\n', void();
		
		for(register int i = 1; i <= n; ++i){
			if(z[a[i]] == '('){
				
				was[i] = a[i] < b[i];
				
				if(a[i] < b[i]){
					z[b[i]] = 'a';
				}else{
					z[a[i]] = 'a';
				}
				
			}else{
				
				was[i] = a[i] > b[i];
				
				if(a[i] > b[i]){
					z[b[i]] = 'a';
				}else{
					z[a[i]] = 'a';
				}
				
			}
		}
		
		string tmp = "";
		
		for(register int i = 0; i < (n << 1); ++i){
			if(z[i] == 'a') continue;
			tmp += z[i];
		}
		
		if(is_valid(tmp)){
			for(register int i = 1; i <= n; ++i){
				cout << was[i] << " \n"[i==n];
			}
		}else{
			cout << -1 << '\n';
		}
		
		
		
		
	};
	while(T--) test_case();
	return 0;	
}

Compilation message

Main.cpp: In function 'bool is_valid(std::string)':
Main.cpp:12:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |  for(register int i = 0; i < (int)s.size(); ++i){
      |                   ^
Main.cpp: In lambda function:
Main.cpp:31:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   31 |   for(register int i = 1; i <= n; ++i){
      |                    ^
Main.cpp:40:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |   for(register int i = 1; i <= n; ++i){
      |                    ^
Main.cpp:66:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   66 |   for(register int i = 0; i < (n << 1); ++i){
      |                    ^
Main.cpp:72:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   72 |    for(register int i = 1; i <= n; ++i){
      |                     ^
Main.cpp:29:20: warning: unused variable 'closings' [-Wunused-variable]
   29 |   int openings(0), closings(0);
      |                    ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -