# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861839 | Aiperiii | parentrises (BOI18_parentrises) | C++17 | 685 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
bool ok(string s,string x){
int cnt=0;
for(int i=0;i<s.size();i++){
if(s[i]=='G' && x[i]=='('){
cnt++;
}
else if(s[i]=='B' && x[i]=='('){
cnt++;
}
else if(s[i]=='B' && x[i]==')'){
cnt--;
if(cnt<0)return false;
}
else if(s[i]=='G' && x[i]==')'){
cnt--;
if(cnt<0)return false;
}
}
if(cnt!=0) return false;
cnt=0;
for(int i=0;i<s.size();i++){
if(s[i]=='G' && x[i]=='('){
cnt++;
}
else if(s[i]=='R' && x[i]=='('){
cnt++;
}
else if(s[i]=='R' && x[i]==')'){
cnt--;
if(cnt<0)return false;
}
else if(s[i]=='G' && x[i]==')'){
cnt--;
if(cnt<0)return false;
}
}
if(cnt!=0) return false;
return true;
}
signed main(){
int p,t;
cin>>p>>t;
if(p==1){
while(t--){
string s;
cin>>s;
string ans="impossible";
queue <string> q;
q.push("");
while(!q.empty()){
string v=q.front();
q.pop();
if(v.size()==s.size()){
if(ok(v,s)){
ans=v;
break;
}
}
else{
q.push(v+'R');
q.push(v+'B');
q.push(v+'G');
}
}
cout<<ans<<"\n";
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |