Submission #74122

#TimeUsernameProblemLanguageResultExecution timeMemory
74122jiajunleeparentrises (BOI18_parentrises)C++14
0 / 100
1078 ms1344 KiB
#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.front().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; } } } if(parent.front().first == ')') { if(i < 0) { GG = true; break; } while(0 <= i) { if(input[i] == ')' && ans[i] == 'G') { ans[i] = 'R'; ans[parent.front().second] = 'B'; parent.pop_front(); 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 (stderr)

parentrises.cpp: In function 'int main()':
parentrises.cpp:56:11: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
           if(SIZE <= j)
           ^~
parentrises.cpp:81:11: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
           if(i < 0)
           ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...