Submission #666927

# Submission time Handle Problem Language Result Execution time Memory
666927 2022-11-29T23:59:30 Z vh50 Superpozicija (COCI22_superpozicija) C++17
0 / 110
57 ms 388 KB
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int MAXN = 1e6;
vector <int> p;
string s;
int n, sum, t, resp[MAXN], v[MAXN], sp[MAXN], ss[MAXN], aux[MAXN];
main()
{
	cin >> t;
	while(t--)
	{
		p.clear();
		cin >> n >> s;
		sum = 0;
		p.clear();
		for(int i = 0; i < 4 * n; i++)	resp[i] = v[i] = sp[i] = ss[i] =aux[i] = 0;
		for(int i = 1; i <= n; i++)
		{
			int a, b;
			cin >> a >> b;
			a--, b--;
			if(s[a] != s[b])	
			{
				p.push_back(i);
				if(s[a] == '(') aux[i] = 0;
				else aux[i] = 1;
			}
			else
			{
				if(s[a] == '(')	sum++, v[i] = 1;
				else	sum--, v[i] = -1;
			}
		}
		int tam = p.size(), f = 0;
		for(int i = 0; i < p.size(); i++)
		{
			int r1 = 0, r2 = 1;
			if(sum + tam - i <= 0 && sum - tam + i >= 0)	
			{
				cout << -1 << endl;
				f = 1;
				break;
			}
			if(sum - tam + i >= 0)
			{
				v[p[i]] = -1;
				if(aux[p[i]])	swap(r1, r2);	
				resp[p[i]] = r2;
				sum--;
			}
			else 
			{
				v[p[i]] = 1;
				if(aux[p[i]])	swap(r1, r2);
				resp[p[i]] = r1;
				sum++;
			}
		}
		for(int i = 1; i <= n; i++)
		{
			sp[i] = sp[i - 1] + v[i];
			if(sp[i] < 0 && !f)
			{
				cout << -1 << endl;
				f = 1;
			}
		}
		for(int i = n; i >= 0; i--)
		{
			ss[i] = ss[i + 1] + v[i];
			if(ss[i] > 0 && !f)
			{
				cout << -1 << endl;
				f = 1;
			}
		}
		if(!f)
		{
			for(int i = 1; i <= n; i++)
			{
				cout << resp[i];
				if(i != n)	cout << " ";
			}
			cout << endl;
		}
	}
}

Compilation message

Main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:37:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i = 0; i < p.size(); i++)
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 388 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 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -