Submission #611598

#TimeUsernameProblemLanguageResultExecution timeMemory
611598amunduzbaevparentrises (BOI18_parentrises)C++17
50 / 100
45 ms7272 KiB
#include "bits/stdc++.h" using namespace std; #define ar array typedef int64_t ll; namespace S1{ const int N = 1e6 + 5; void solve(){ string s; cin >> s; int n = s.size(); vector<int> p, is(n); for(int i=0;i<n;i++){ int v = (s[i] == ')'); if(v && !p.empty()){ is[p.back()] = is[i] = 1; p.pop_back(); } else if(!v) { p.push_back(i); } } deque<int> q; for(int i=0;i<n;i++){ if(!is[i]) q.push_back(i); } for(int i=0;i<n && !q.empty();i++){ if(!is[i]) continue; if(s[q.front()] == ')'){ if(s[i] == '(' && i < q.front()){ is[i] = 2; q.pop_front(); } } else { if(s[i] == ')' && i > q.front()){ is[i] = 2; q.pop_front(); } } } if(!q.empty()){ cout<<"impossible\n"; return; } for(int i=0;i<n;i++){ if(is[i] == 0) cout<<"R"; if(is[i] == 1) cout<<"B"; if(is[i] == 2) cout<<"G"; } cout<<"\n"; } void main(){ int t; cin >> t; while(t--){ solve(); } } }; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; if(T == 1){ S1::main(); } }
#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...