Submission #74106

# Submission time Handle Problem Language Result Execution time Memory
74106 2018-08-30T06:02:09 Z zscoder parentrises (BOI18_parentrises) C++17
11 / 100
3 ms 712 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int ans[1111111];

bool solve(string &s)
{
	int n=s.length();
	for(int i=0;i<n;i++) ans[i]=0;
	int ptr = 0;
	stack<int> S;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='(')
		{
			S.push(i);
		}
		else
		{
			if(!S.empty())
			{
				int u=S.top();
				ans[i]|=1; ans[u]|=1; S.pop();
			}
			else
			{
				while(ptr<i&&(s[ptr]!='('||ans[ptr]>=3)) ptr++;
				if(ptr>=i) return 0;
				ans[ptr]|=2; ans[i]|=2; 
			}
		}
	}
	ptr=n-1;
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]==')'||ans[i]>0) continue;
		while(ptr>i&&(s[ptr]!=')'||ans[ptr]>=3)) ptr--;
		ans[i]|=2; ans[ptr]|=2;
	}
	return 1;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int type; cin>>type;
	int t; cin>>t;
	while(t--)
	{
		if(type==1)
		{
			string s; cin>>s; 
			bool tmp = solve(s);
			
			if(!tmp) 
			{
				cout<<"impossible\n"; 
				continue;
			}
			for(int i=0;i<s.length();i++)
			{
				if(ans[i]==1) cout<<"B";
				else if(ans[i]==2) cout<<"R";
				else cout<<"G";
			}
			cout<<'\n';
		}
		else
		{
			int n; cin>>n;
			
		}
	}
}	

Compilation message

parentrises.cpp: In function 'int main()':
parentrises.cpp:75:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<s.length();i++)
                ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 616 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 616 KB Output is correct
2 Correct 2 ms 652 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 2 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 616 KB Output is correct
2 Correct 2 ms 652 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 2 ms 700 KB Output is correct
6 Incorrect 2 ms 708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 616 KB Output is correct
2 Correct 2 ms 652 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 2 ms 700 KB Output is correct
6 Incorrect 2 ms 708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 712 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 712 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 712 KB Unexpected end of file - int32 expected