# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66374 | KLPP | Igra (COCI17_igra) | C++14 | 67 ms | 712 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<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdio.h>
using namespace std;
string s,m;
int n;
bool check(int pos,int a, int b, int c){
if(a<0 || b<0 || c<0)return false;
int A=a;
int B=b;
int C=c;
for(int i=pos;i<n;i++){
if(m.at(i)=='a')A++;
if(m.at(i)=='b')B++;
if(m.at(i)=='c')C++;
}
if(A>n-pos || B>n-pos || C>n-pos)return false;
return true;
}
int main(){
cin>>n;
cin>>s;
cin>>m;
int a,b,c;
a=0;
b=0;
c=0;
for(int i=0;i<n;i++){
if(s.at(i)=='a')a++;
if(s.at(i)=='b')b++;
if(s.at(i)=='c')c++;
}
string ans;
for(int i=0;i<n;i++){
if(m.at(i)=='a'){
if(check(i+1,a,b-1,c)){
b--;
ans+='b';
}else{
c--;
ans+='c';
}
}
if(m.at(i)=='b'){
if(check(i+1,a-1,b,c)){
a--;
ans+='a';
}else{
c--;
ans+='c';
}
}
if(m.at(i)=='c'){
if(check(i+1,a-1,b,c)){
a--;
ans+='a';
}else{
b--;
ans+='b';
}
}
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |