# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81990 | Vasiljko | Igra (COCI17_igra) | C++14 | 3 ms | 652 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;
typedef long long ll;
const ll MOD = 1e9+7;
int n,a,b,c,cura,curb,curc;
string s,t;
vector<char>ans;
bool check(int fi,int se,int th){
if(fi+se>=curc&&fi+th>=curb&&se+th>=cura)return true;
return false;
}
void Set(int ind,char p,int &val){
ans[ind]=p;
val--;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;
cin>>s>>t;
ans.resize(n);
for(int i=0;i<n;i++){
if(s[i]=='a')a++;
else if(s[i]=='b')b++;
else c++;
}
for(int i=0;i<n;i++){
if(t[i]=='a')cura++;
else if(t[i]=='b')curb++;
else curc++;
}
for(int i=0;i<n;i++){
if(t[i]=='a'){
cura--;
bool ok1=check(a,b-1,c);
bool ok2=check(a,b,c-1);
if(ok1&&ok2)Set(i,'b',b);
else{
if(ok1)Set(i,'b',b);
else Set(i,'c',c);
}
}else if(t[i]=='b'){
curb--;
bool ok1=check(a-1,b,c);
bool ok2=check(a,b,c-1);
if(ok1&&ok2)Set(i,'a',a);
else{
if(ok1)Set(i,'a',a);
else Set(i,'c',c);
}
}else{
curc--;
bool ok1=check(a-1,b,c);
bool ok2=check(a,b-1,c);
if(ok1&&ok2)Set(i,'a',a);
else{
if(ok1)Set(i,'a',a);
else Set(i,'b',b);
}
}
}
for(auto e:ans)cout<<e;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |