Submission #63509

#TimeUsernameProblemLanguageResultExecution timeMemory
63509Bruteforcemanparentrises (BOI18_parentrises)C++11
50 / 100
52 ms5708 KiB
#include "bits/stdc++.h" using namespace std; // vector <char> v[1000010]; string solve(string s) { int n = s.size(); stack <int> p; stack <int> q; string ans; for(int i = 0; i < n; i++) ans += '#'; for(int i = 0; i < n; i++) { if(s[i] == ')') { if(p.empty()) { if(q.empty()) return "impossible"; else { ans[q.top()] = 'G'; ans[i] = 'B'; q.pop(); } } else { ans[p.top()] = 'R'; ans[i] = 'R'; p.pop(); } } else { p.push(i); q.push(i); } } stack <int> thic; for(int i = 0; i < n; i++) { if(ans[i] == '#') { thic.push(i); } else if (s[i] == ')' && !thic.empty()) { ans[thic.top()] = 'B'; ans[i] = 'G'; thic.pop(); } } if(thic.empty()) return ans; else return "impossible"; } int main(int argc, char const *argv[]) { ios_base :: sync_with_stdio (false); cin.tie(0); int p; cin >> p; assert(p == 1); int t; cin >> t; while(t--) { string s; cin >> s; cout << solve(s) << '\n'; } return 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...