Submission #98568

#TimeUsernameProblemLanguageResultExecution timeMemory
98568tdwnparentrises (BOI18_parentrises)C++17
0 / 100
3 ms384 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; string code; string answ; string fin; string solve(string 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()] = 'B'; answ[i] = 'B'; s2.push(s1.top()); s1.pop(); } else if(s2.size() > 0){ answ[s2.top()] = 'G'; answ[i] = 'R'; s2.pop(); } } } return answ; } bool invalid(char a, char b) { return (a == '(' && b == a) || (a == ')' && b == a) || (a == 'R' && b == 'B') || (a == 'B' && b == 'R'); } void solvea() { cin>>code; string f = solve(code); reverse(code.begin(), code.end()); for(int i=0;i<code.length();i++) { if(code[i] == '(') code[i] = ')'; else code[i] = '('; } string s = solve(code); reverse(s.begin(), s.end()); // merge them string answ = f; for(int i=0;i<f.length();i++) { if(invalid(s[i], f[i])) { cout<<"Impossible\n"; return; } else { if(s[i] == 'G' || f[i] == 'G') answ[i] = 'G'; else if(s[i] == f[i]) answ[i] = s[i]; else if((s[i] != '(' && s[i] != ')') && (f[i] =='(' || f[i] == ')')) answ[i] = s[i]; else if((f[i] != '(' && f[i] != ')') && (s[i] =='(' || s[i] == ')')) answ[i] = f[i]; } if(answ[i] == '(' || answ[i] == ')') { cout<<"Impossible\n"; return; } } cout<<answ<<"\n"; } void solveb() { cout<<"0\n"; } int main() { int P, T; cin>>P; cin>>T; while(T--) { if(P == 1) solvea(); else solveb(); } return 0; }

Compilation message (stderr)

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