# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112585 | ioilolcom | Igra (COCI17_igra) | C++14 | 2 ms | 384 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 endl "\n"
typedef long long int ll;
int pi[4],u[4];
bool check(){
return (u[1]+u[2]>=pi[0])&&(u[2]+u[0]>=pi[1])&&(u[1]+u[0]>=pi[2]);
}
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
int n; cin>>n;
string a,b;
string ans="";
cin>>a>>b;
for(int i=0; i<n; i++) {
u[a[i]-'a']++;
pi[b[i]-'a']++;
}
//
//string ans="";
// how can i know if a solution exist if i take a char a
//cout<<u[0]<<" "<<u[1]<<" "<<u[2]<<endl;
for(int i=0; i<n; i++) {
for(int j=0; j<3; j++) {
if(j!=b[i]-'a') {
if(u[j]) {
u[j]--;
pi[b[i]-'a']--;
if(!check()) {
u[j]++; pi[a[i]-'a']++;
continue;
}
ans+=(char)(j+'a');
break;
}
}
}
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |