Submission #666809

# Submission time Handle Problem Language Result Execution time Memory
666809 2022-11-29T18:37:08 Z vh50 Superpozicija (COCI22_superpozicija) C++17
0 / 110
66 ms 400 KB
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int MAXN = 2e5;
string s;
int v[MAXN], ls[MAXN], rs[MAXN], aux[MAXN];
int t, n;
main()
{
	cin >> t;
	while(t--)
	{
		int c, f;
		c = f = 0;
		cin >> n >> s;
		for(int i = 0; i < 2 * n; i++)	v[i] = ls[i] = rs[i] = aux[i] = 0;
		for(int i = 0; i < n; i++)
		{
			int a, b;
			cin >> a >> b;
			a--, b--;
			if(s[a] != s[b])
			{
				if(s[a] == ')')	aux[i]++;
				continue;
			}
			if(s[a] == '(')	v[i] = -1;
			else v[i] = 1;
		}
		if(n % 2 == 1)	{cout << -1 << endl; f = 1;}
		for(int i = 0; i < n; i++)
		{
			if(i != 0)	ls[i] = ls[i - 1] + v[i];
			else ls[i] = v[i];
			if(!v[i])	c++;
			if(c + ls[i] < 0 && !f)	
			{
				cout << -1 << endl;
				f = 1;
				break;
			}
		}
		c = 0;
		for(int i = n - 1; i >= 0; i--)
		{
			if(i != n - 1)	rs[i] = rs[i + 1] + v[i];
			else	rs[i] = v[i];
			if(!v[i])	c++;
			if(c + rs[i] < 0 && !f)	
			{
				cout << -1 << endl;
				f = 1;
				break;
			}
		}
		int sum = 0;
		if(!f)
		{
			for(int i = 0; i < n; i++)
			{
				if(v[i])	cout << 0 << " ";
				else
				{
					int r1 = 0, r2 = 1;
					if(aux[i])	swap(r1, r2);
					if(ls[i] - rs[i] + sum <= 0)	{cout << r1 << " "; sum++;}
					else	{cout << r2 << " "; sum--;}
				}
			}
			cout << endl;
		}
	}
}

Compilation message

Main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -