# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151742 | hdj79 | Igra (COCI17_igra) | C++14 | 4 ms | 504 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<string>
using namespace std;
bool moze(int a,int b,int c,int A,int B,int C){
int sa=a,sb=b,sc=c,sA=A,sB=B,sC=C;
// cout<<a<<" "<<b<<" "<<c<<" "<<A<<" "<<B<<" "<<C<<endl;
for(int k=0;k<=B;k++){
a-=k;
B-=k;
if(a<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
C-=a;
a=0;
if(C<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
b-=C;
C=0;
if(b<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
A-=b;
b=0;
if(A<0) {a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
c-=A;
A=0;
if(c<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
//cout<<a<<" "<<b<<" "<<c<<" "<<A<<" "<<B<<" "<<C<<endl;
if(c==B) return true;
}
return false;
}
int main(){
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string r;
string mr;
string sol="";
cin>>r>>mr;
int a=0,b=0,c=0,A=0,B=0,C=0;
for(int i=0;i<n;i++){
if(r[i]=='a') a++;
if(r[i]=='b') b++;
if(r[i]=='c') c++;
if(mr[i]=='a') A++;
if(mr[i]=='b') B++;
if(mr[i]=='c') C++;
}
for(int i=0;i<n;i++){
if(mr[i]=='a') A--;
if(mr[i]=='b') B--;
if(mr[i]=='c') C--;
for(int j=0;j<3;j++){
if(j+'a'==mr[i]) continue;
if(j==0) a--;
if(j==1) b--;
if(j==2) c--;
if(moze(a,b,c,A,B,C)){
sol.push_back(j+'a');
break;
}
else{
if(j==0) a++;
if(j==1) b++;
if(j==2) c++;
}
}
}
cout<<sol;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |