Submission #98573

#TimeUsernameProblemLanguageResultExecution timeMemory
98573tdwnparentrises (BOI18_parentrises)C++17
50 / 100
225 ms7400 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; string code; void solve() { cin>>code; string answ = code; stack<int>s1, s2; for(int i=0;i<code.length();i++) { if(code[i] == '(') { s1.push(i); } else { if(s1.size() > 0) { answ[s1.top()] = answ[i] = 'R'; s2.push(s1.top()); s1.pop(); } else if(s2.size() > 0) { answ[s2.top()] = 'G'; answ[i] = 'B'; s2.pop(); } else { cout<<"impossible\n"; return; } } } stack<int>t1, t2; for(int i=code.length()-1;i>=0;i--) { if(code[i] == ')') { t1.push(i); } else { if(answ[i] == 'R' || answ[i] == 'G') continue; else { if(t1.size() > 0) { answ[i] = 'B'; answ[t1.top()] = 'G'; t1.pop(); } else { cout<<"impossible\n"; return; } } } } cout<<answ<<"\n"; return; } int main() { int P, T; cin>>P; cin>>T; while(T--) { solve(); } return 0; }

Compilation message (stderr)

parentrises.cpp: In function 'void solve()':
parentrises.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<code.length();i++) {
                 ~^~~~~~~~~~~~~~
#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...