Submission #255155

# Submission time Handle Problem Language Result Execution time Memory
255155 2020-07-31T12:28:55 Z Saboon parentrises (BOI18_parentrises) C++14
100 / 100
311 ms 214648 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 1e6 + 10;
const int N = 300 + 2;
const int mod = 1e9 + 7;
int l[maxn], r[maxn];
int dp[N][N][2*N], sumdp[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int type;
	cin >> type;
	if (type == 1){
		int tc;
		cin >> tc;
		while (tc --){
			string s;
			cin >> s;
			int L = 0, R = 0;
			int n = s.size();
			bool flag = 0;
			for (int i = n-1; i >= 0; i--){
				if (s[i] == ')')
					L ++, R += 2;
				else{
					if (R == 0){
						flag = 1;
						break;
					}
					L = max(0, L-2);
					R --;
				}
				l[i] = L, r[i] = R;
			}
			if (flag == 1 or L > 0){
				cout << "impossible\n";
				continue;
			}
			l[n] = r[n] = 0;
			int now = 0;
			bool Red1 = 1, Red2 = 1; 
			for (int i = 0; i < n; i++){
				if (s[i] == '('){
					if (l[i+1] <= now+1 and now+1 <= r[i+1]){
						if (Red1)
							cout << 'R';
						else
							cout << 'B';
						Red1 ^= 1;
						now ++;
					}
					else{
						cout << 'G';
						now += 2;
					}
				}
				else{
					if (l[i+1] <= now-1 and now-1 <= r[i+1]){
						if (Red2)
							cout << 'R';
						else
							cout << 'B';
						Red2 ^= 1;
						now --;
					}
					else{
						cout << 'G';
						now -= 2;
					}
				}
			}
			cout << '\n';
		}
	}
	else{
		int n = 300;
		dp[0][0][0] = 1;
		for (int i = 0; i < n; i++){
			for (int l = 0; l <= n; l++){
				for (int r = l; r <= 2*n; r++){
					dp[i+1][l+1][r+2] = (dp[i+1][l+1][r+2] + dp[i][l][r]) % mod;
					if (r > 0)
						dp[i+1][max(0,l-2)][r-1] = (dp[i+1][max(0,l-2)][r-1] + dp[i][l][r]) % mod;
				}
			}
		}
		for (int i = 1; i <= n; i++)
			for (int r = 0; r <= 2*n; r++)
				sumdp[i] = (sumdp[i] + dp[i][0][r]) % mod;
		int tc;
		cin >> tc;
		while (tc --){
			int n;
			cin >> n;
			cout << sumdp[n] << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 19 ms 384 KB Output is correct
17 Correct 5 ms 1408 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 4 ms 1012 KB Output is correct
20 Correct 5 ms 1408 KB Output is correct
21 Correct 140 ms 1164 KB Output is correct
22 Correct 44 ms 10256 KB Output is correct
23 Correct 28 ms 2092 KB Output is correct
24 Correct 34 ms 5460 KB Output is correct
25 Correct 44 ms 10260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 214648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 214648 KB Output is correct
2 Correct 304 ms 214428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 214648 KB Output is correct
2 Correct 304 ms 214428 KB Output is correct
3 Correct 311 ms 214532 KB Output is correct