# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
365451 | 2021-02-11T17:11:29 Z | lookcook | parentrises (BOI18_parentrises) | C++17 | 66 ms | 4360 KB |
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 1000005; char res[maxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int p, t; cin >> p >> t; if (p == 1) { while (t--) { string s; cin >> s; bool ok = true; bool turn = true; int sr = 0; int sb = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '(') { res[i] = 'G'; sr++; sb++; } else { if (turn) { res[i] = 'R'; sr--; } else { res[i] = 'B'; sb--; } turn = !turn; } if (sr < 0 || sb < 0) ok = false; } if (sb>sr) { for (int i = s.length()-1; i >= 0; i--) { if (s[i] == '(') { res[i] = 'R'; break; } if (s[i] == ')' && res[i] == 'R') { res[i] = 'G'; break; } } } sr = 0; sb = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == ')') { if (res[i] == 'G') { sr--; sb--; } if (res[i] == 'R') sr--; if (res[i] == 'B') sb--; } else { if (res[i] == 'G') { sr++; sb++; } if (res[i] == 'R') sr++; if (res[i] == 'B') sb++; } if (sr < 0 || sb < 0) ok = false; } for (int i = s.length()-1; i >= 0; i--) { if (s[i] == '(' && res[i] == 'G') { if (sr>=sb && sr>0) { // maybe swap order? sr--; res[i] = 'B'; } else if (sb > 0) { sb--; res[i] = 'R'; } } if (s[i] == ')') { if (res[i] == 'R' && sb>0) { res[i] = 'G'; sb--; } else if (res[i] == 'B' && sr>0) { res[i] = 'G'; sr--; } } } sr = 0; sb = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == ')') { if (res[i] == 'G') { sr--; sb--; } if (res[i] == 'R') sr--; if (res[i] == 'B') sb--; } else { if (res[i] == 'G') { sr++; sb++; } if (res[i] == 'R') sr++; if (res[i] == 'B') sb++; } if (sr < 0 || sb < 0) ok = false; } if (ok && sr==0&&sb==0) { for (int i = 0; i < s.length(); i++) cout << res[i]; cout << '\n'; } else { cout << "impossible\n"; } } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 512 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 6 ms | 492 KB | Output is correct |
17 | Correct | 9 ms | 876 KB | Output is correct |
18 | Correct | 5 ms | 492 KB | Output is correct |
19 | Correct | 7 ms | 748 KB | Output is correct |
20 | Correct | 7 ms | 876 KB | Output is correct |
21 | Correct | 49 ms | 2156 KB | Output is correct |
22 | Correct | 66 ms | 4360 KB | Output is correct |
23 | Correct | 50 ms | 2488 KB | Output is correct |
24 | Correct | 57 ms | 2880 KB | Output is correct |
25 | Correct | 64 ms | 4360 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Unexpected end of file - int32 expected |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Unexpected end of file - int32 expected |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Unexpected end of file - int32 expected |