Submission #61249

#TimeUsernameProblemLanguageResultExecution timeMemory
61249Miyukineparentrises (BOI18_parentrises)C++14
50 / 100
78 ms3700 KiB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<=(b); ++i)
const int maxn = 1e6 + 5;
typedef pair <int, int> PII;
typedef long long ll;
const int mod = 1e9 + 7;

ll dp[2][305][305];
//dp[length][stacksize in RG][stacksize in RB]
int type, n;
string s;
int stos[1000100], DL = 0;
char arr[1000100];

void solveone()
{
	cin >> s;
	int m = (int)s.size();
	DL = 0;
	for (int i = 0; i < m; ++i)
	{
		if (s[i] == '(') stos[++DL] = i, arr[i] = 'R';
		else
		{
			if (DL > 0) 
			{
				arr[stos[DL]] = 'B';
				arr[i] = 'B';
				DL--;
			}
			else arr[i] = 'R';
		}
	}
	
	int wait = 0;
	for (int i = 0; i < m; ++i)
		if (arr[i] == 'R' && s[i] == '(') ++wait;
		else if (arr[i] == 'B' && s[i] == ')' && wait > 0)
		{
			--wait;
			arr[i] = 'G';
		}
	
	if (wait > 0)
	{
		cout << "impossible\n";
		return;
	}
	wait = 0;
	for (int i = m - 1; i >= 0; --i)
	{
		if (arr[i] == 'R' && s[i] == ')') ++wait;
		else if (arr[i] == 'B' && s[i] == '(' && wait > 0)
		{
			--wait;
			arr[i] = 'G';
		}
	}
	if (wait > 0)
	{
		cout << "impossible\n";
		return;
	}
	
	for (int i = 0; i < m; ++i) cout << arr[i];
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> type;
	if (type == 1)
	{
		cin >> n;
		for (int i=0; i<n; ++i) solveone();
	}
	if (type == 2)
	{
		cin >> n;
		dp[0][0][0] = 1; //one sequence
		for (int i=1; i<=n; ++i)
		{
			FOR(j, 0, n)
				FOR(k, 0, n) dp[i & 1][j][k] = 0;
			
			
			//FOR(j, 0, n)
				//FOR(k, 0, n) dp[(i & 1) ^ 1][j][k]
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...