# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62018 | 2018-07-27T08:56:26 Z | gs14004 | parentrises (BOI18_parentrises) | C++17 | 3 ms | 480 KB |
#include<bits/stdc++.h> using namespace std; using pi = pair<int, int>; using lint = long long; const int MAXN = 1000050; bool Do(string s, string cert){ int c0 = 0, c1 = 0; for(int i=0; i<s.size(); i++){ if(s[i] == '('){ if(cert[i] != 'B') c0++; if(cert[i] != 'R') c1++; } else{ if(cert[i] != 'B') c0--; if(cert[i] != 'R') c1--; if(c0 < 0 || c1 < 0) return 0; } } if(c0 == 0 && c1 == 0) return 1; return 0; } string solve(string s){ queue<int> que; string chk; int cnt = 0; chk.resize(s.size()); for(int i=0; i<s.size(); i++){ if(s[i] == '('){ que.push(i); cnt++; chk[i] = '?'; } else{ if(cnt > 0){ chk[i] = '!'; cnt--; } else{ if(que.empty()) return "impossible"; int x = que.front(); que.pop(); chk[x] = 'G'; chk[i] = '!'; } } } cnt = 0; for(int i=0; i<s.size(); i++){ if(s[i] == '('){ if(chk[i] == 'G') cnt += 2; else{ cnt++; if(cnt & 1) chk[i] = 'R'; else chk[i] = 'B'; } } else{ if(cnt & 1) chk[i] = 'R'; else chk[i] = 'B'; cnt--; } } for(int i=(int)s.size()-1; i>=0; i--){ if(s[i] == ')' && cnt){ chk[i] = 'G'; cnt--; } } if(Do(s, chk)) return chk; else return "impossible"; } int f(int x){ return x; } int main(){ char buf[MAXN]; int p, t; cin >> p; if(p == 1){ scanf("%d",&t); while(t--){ scanf("%s",buf); string ans = buf; printf("%s\n", solve(buf).c_str()); } } else{ scanf("%d",&t); while(t--){ int n; cin >> n; cout << f(n) << endl; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 416 KB | Output is correct |
2 | Incorrect | 2 ms | 468 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 480 KB | Output is correct |
2 | Incorrect | 2 ms | 480 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 480 KB | Output is correct |
2 | Incorrect | 2 ms | 480 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 480 KB | Output is correct |
2 | Incorrect | 2 ms | 480 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 480 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 480 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 480 KB | Output isn't correct |