# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
65171 | 2018-08-06T23:31:06 Z | spencercompton | parentrises (BOI18_parentrises) | C++14 | 216 ms | 11540 KB |
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int p, cases; cin >> p >> cases; if(p==1){ for(int z = 1; z<=cases; z++){ string s; cin >> s; bool pos = true; int open = 0; int close = 0; for(int i = 0; i<s.length(); i++){ if(s[i]=='('){ open++; } else{ close++; } if(close>2*open){ pos = false; } } open = 0; close = 0; for(int i = s.length()-1; i>=0; i--){ if(s[i]=='('){ open++; } else{ close++; } if(open > 2*close){ pos = false; } } int n = (int)s.length(); int color[n]; //G = 0, B = 1, R = 2 for(int i = 0; i<n; i++){ color[i] = 0; } open = 0; close = 0; vector<int> op; vector<int> cl; bool ok = true; vector<int> op2; vector<int> cl2; int point = 0; for(int i = 0; i<n; i++){ if(s[i]=='('){ op.push_back(i); open++; } else{ cl.push_back(i); close++; if(close>open){ if(point+2 > cl.size()){ ok = false; break; } cl2.push_back(cl[point++]); cl2.push_back(cl[point++]); close--; } } } int dif = open-close; if(!ok || 2*dif>open){ assert(!pos); cout << "impossible" << endl; continue; } for(int i = 0; i<2*dif; i++){ op2.push_back(op.back()); op.pop_back(); } assert(op2.size()%2==0 && cl2.size()%2==0); for(int i = 0; i<op2.size(); i+=2){ color[op2[i]] = 1; color[op2[i+1]] = 2; } for(int i = 0; i<cl2.size(); i+=2){ color[cl2[i]] = 1; color[cl2[i+1]] = 2; } int bal1 = 0; int bal2 = 0; for(int i = 0; i<n; i++){ if(color[i]==0 || color[i]==1){ if(s[i]=='('){ bal1++; } else{ bal1--; } } if(color[i]==0 || color[i]==2){ if(s[i]=='('){ bal2++; } else{ bal2--; } } if(bal1<0 || bal2<0){ ok = false; } } ok &= bal1==0 && bal2==0; if(!ok){ assert(!pos); cout << "impossible" << endl; continue; } assert(ok); for(int i = 0; i<n; i++){ if(color[i]==0){ cout << "G"; } else if(color[i]==1){ cout << "B"; } else{ cout << "R"; } } cout << endl; } } else{ assert(false); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 360 KB | Output is correct |
3 | Correct | 2 ms | 568 KB | Output is correct |
4 | Correct | 3 ms | 652 KB | Output is correct |
5 | Correct | 2 ms | 652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 652 KB | Output is correct |
2 | Correct | 2 ms | 652 KB | Output is correct |
3 | Correct | 2 ms | 652 KB | Output is correct |
4 | Correct | 3 ms | 652 KB | Output is correct |
5 | Correct | 3 ms | 652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 652 KB | Output is correct |
2 | Correct | 2 ms | 652 KB | Output is correct |
3 | Correct | 2 ms | 652 KB | Output is correct |
4 | Correct | 3 ms | 652 KB | Output is correct |
5 | Correct | 3 ms | 652 KB | Output is correct |
6 | Correct | 3 ms | 660 KB | Output is correct |
7 | Correct | 3 ms | 664 KB | Output is correct |
8 | Correct | 3 ms | 668 KB | Output is correct |
9 | Correct | 3 ms | 672 KB | Output is correct |
10 | Correct | 3 ms | 676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 652 KB | Output is correct |
2 | Correct | 2 ms | 652 KB | Output is correct |
3 | Correct | 2 ms | 652 KB | Output is correct |
4 | Correct | 3 ms | 652 KB | Output is correct |
5 | Correct | 3 ms | 652 KB | Output is correct |
6 | Correct | 3 ms | 660 KB | Output is correct |
7 | Correct | 3 ms | 664 KB | Output is correct |
8 | Correct | 3 ms | 668 KB | Output is correct |
9 | Correct | 3 ms | 672 KB | Output is correct |
10 | Correct | 3 ms | 676 KB | Output is correct |
11 | Correct | 4 ms | 680 KB | Output is correct |
12 | Correct | 4 ms | 820 KB | Output is correct |
13 | Correct | 4 ms | 820 KB | Output is correct |
14 | Correct | 5 ms | 820 KB | Output is correct |
15 | Correct | 5 ms | 904 KB | Output is correct |
16 | Correct | 24 ms | 932 KB | Output is correct |
17 | Correct | 9 ms | 2028 KB | Output is correct |
18 | Correct | 8 ms | 2028 KB | Output is correct |
19 | Correct | 10 ms | 2028 KB | Output is correct |
20 | Correct | 10 ms | 2096 KB | Output is correct |
21 | Correct | 216 ms | 2096 KB | Output is correct |
22 | Correct | 87 ms | 11540 KB | Output is correct |
23 | Correct | 49 ms | 11540 KB | Output is correct |
24 | Correct | 60 ms | 11540 KB | Output is correct |
25 | Correct | 69 ms | 11540 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 11540 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 11540 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 11540 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |