# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74117 | 2018-08-30T06:40:20 Z | jiajunlee | parentrises (BOI18_parentrises) | C++14 | 3 ms | 1404 KB |
#include <iostream> #include <cstring> #include <stack> #include <deque> using namespace std; typedef long long LL; const LL MAXN = 1000 * 1005; const LL MOD = (1000 * 1000 * 1000) + 7; LL type, t; LL SIZE; string input, nono = {"impossible"}; int main(void) { cin >> type >> t; if(type == 1) { string temp; getline(cin, temp); for(LL i0 = 0; i0 < t; i0++) { getline(cin, input); //cout << input << endl; SIZE = input.size(); deque<pair<char, LL> > parent = {}; char ans[MAXN] = {}; bool GG = false; for(LL idx = 0; idx < SIZE; idx++) { if(!parent.empty() && parent.back().first == '(' && input[idx] == ')') { ans[parent.back().second] = 'G'; ans[idx] = 'G'; parent.pop_back(); }else parent.push_back(make_pair(input[idx], idx)); } //cout << "normal" << endl; LL i, j; if(!parent.empty() ) { i = parent.back().second-1; j = parent.back().second+1; } while(!parent.empty() ) { i = min(i, parent.back().second-1); j = max(j, parent.back().second+1); if(GG)break; if(parent.back().first == '(') { if(SIZE <= j) { GG = true; break; } while(j < SIZE) { if(input[j] == '(' && ans[j] == 'G') { ans[j] = 'R'; ans[parent.back().second] = 'B'; parent.pop_back(); j++; break; } j++; if(SIZE <= j) { GG = true; break; } } }else { if(i < 0) { GG = true; break; } while(0 <= i) { if(input[i] == ')' && ans[i] == 'G') { ans[i] = 'R'; ans[parent.back().second] = 'B'; parent.pop_back(); i--; break; } i--; if(i < 0) { GG = true; break; } } } } //cout << "FIN" << endl; if(GG || !parent.empty())cout << nono << endl; else { for(LL idx = 0; idx < SIZE; idx++) { cout << ans[idx]; } cout << endl; } } }else { } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1276 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1404 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1404 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 1404 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 1404 KB | Unexpected end of file - int32 expected |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 1404 KB | Unexpected end of file - int32 expected |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 1404 KB | Unexpected end of file - int32 expected |