# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
61976 | 2018-07-27T07:13:07 Z | ainta(#1792) | parentrises (BOI18_parentrises) | C++11 | 252 ms | 134076 KB |
#include<cstdio> #include<algorithm> #include<queue> #define N_ 1010000 using namespace std; char p[N_]; int n, S[N_], v[N_]; int A[N_], B[N_], CA, CB; void Do() { int i; S[0] = 0; CA = CB = 0; for (i = 0; p[i]; i++) { S[i + 1] = S[i]; v[i] = 0; if (p[i] == '(') { S[i + 1]++; A[CA++] = i; } else { S[i + 1]--; B[CB++] = i; } } n = i; for (i = 0; i <= n; i++) { if ((-S[i]) * 3 > i) { puts("impossible"); return; } if ((S[n] - S[i]) * 3 > (n - i)) { puts("impossible"); return; } } if (S[n] > 0) { int TT = S[n]; for (i = 0; i < TT; i++) { v[B[CB - 1 - i]] = 1; } int pv1 = 0, pv2 = CB - 1 - TT; while (pv1 < CA && pv2 >= 0 && A[pv1] < B[pv2]) { v[A[pv1]] = v[B[pv2]] = 1; pv2--, pv1++; } } else { int TT = -S[n]; for (i = 0; i < TT; i++)v[A[i]] = 1; int pv1 = TT, pv2 = CB - 1; while (pv1 < CA && pv2 >= 0 && A[pv1] < B[pv2]) { v[A[pv1]] = v[B[pv2]] = 1; pv2--, pv1++; } } int s1 = 0, s2 = 0; for (i = 0; i < n; i++) { int ck = 0; if (p[i] == '(')ck = 1; else ck = -1; if (v[i] == 1) { s1 += ck, s2 += ck; } else { if (ck == 1) { if (s1 < s2) { s1 += ck; v[i] = 0; } else { s2 += ck; v[i] = 2; } } else { if (s1 > s2) { s1 += ck; v[i] = 0; } else { s2 += ck; v[i] = 2; } } } if (s1 < 0 || s2<0) { puts("impossible"); return; } } for (i = 0; i < n; i++) { if (v[i] == 0)printf("R"); if (v[i] == 1)printf("G"); if (v[i] == 2)printf("B"); } puts(""); } void Solve1() { int TC, i; scanf("%d", &TC); while (TC--) { scanf("%s", p); Do(); } } int D[310][410][610], Res[310], Mod = 1000000007; void Calc() { int i, j, k; D[0][100][600] = 1; for (i = 0; i <= 300; i++) { for (j = 100 - i / 3; j <= 100 + i; j++) { for (k = 600; k >= 600-2*i; k--) { int s = j - 100, t = D[i][j][k]; if (!t)continue; if (k - 600 == s * 3 - i)Res[i] = (Res[i] + t) % Mod; if (i == 300)continue; D[i + 1][j + 1][k] = (D[i + 1][j + 1][k] + t) % Mod; int kk = min(k, (s - 1) * 3 - (i + 1) + 600); if(kk>=0)D[i + 1][j - 1][kk] = (D[i + 1][j - 1][kk] + t) % Mod; } } } } void Solve2() { int i, TC, n; Calc(); scanf("%d", &TC); while (TC--) { scanf("%d", &n); printf("%d\n", Res[n]); } } int main() { //freopen("input.txt", "r", stdin); int ck; scanf("%d", &ck); if (ck == 1) { Solve1(); } else { Solve2(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 484 KB | Output is correct |
3 | Correct | 3 ms | 484 KB | Output is correct |
4 | Correct | 3 ms | 612 KB | Output is correct |
5 | Correct | 2 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 2 ms | 640 KB | Output is correct |
3 | Correct | 4 ms | 640 KB | Output is correct |
4 | Correct | 5 ms | 640 KB | Output is correct |
5 | Correct | 3 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 2 ms | 640 KB | Output is correct |
3 | Correct | 4 ms | 640 KB | Output is correct |
4 | Correct | 5 ms | 640 KB | Output is correct |
5 | Correct | 3 ms | 640 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 3 ms | 640 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 3 ms | 640 KB | Output is correct |
10 | Correct | 3 ms | 704 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 640 KB | Output is correct |
2 | Correct | 2 ms | 640 KB | Output is correct |
3 | Correct | 4 ms | 640 KB | Output is correct |
4 | Correct | 5 ms | 640 KB | Output is correct |
5 | Correct | 3 ms | 640 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 3 ms | 640 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 3 ms | 640 KB | Output is correct |
10 | Correct | 3 ms | 704 KB | Output is correct |
11 | Correct | 3 ms | 720 KB | Output is correct |
12 | Correct | 4 ms | 764 KB | Output is correct |
13 | Correct | 3 ms | 764 KB | Output is correct |
14 | Correct | 3 ms | 764 KB | Output is correct |
15 | Correct | 3 ms | 832 KB | Output is correct |
16 | Correct | 7 ms | 832 KB | Output is correct |
17 | Correct | 14 ms | 1980 KB | Output is correct |
18 | Correct | 9 ms | 1980 KB | Output is correct |
19 | Correct | 11 ms | 1980 KB | Output is correct |
20 | Correct | 12 ms | 1980 KB | Output is correct |
21 | Correct | 52 ms | 1980 KB | Output is correct |
22 | Correct | 106 ms | 14392 KB | Output is correct |
23 | Correct | 65 ms | 14392 KB | Output is correct |
24 | Correct | 70 ms | 14392 KB | Output is correct |
25 | Correct | 92 ms | 14396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 211 ms | 134076 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 211 ms | 134076 KB | Output is correct |
2 | Correct | 191 ms | 134076 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 211 ms | 134076 KB | Output is correct |
2 | Correct | 191 ms | 134076 KB | Output is correct |
3 | Correct | 252 ms | 134076 KB | Output is correct |