Submission #170597

#TimeUsernameProblemLanguageResultExecution timeMemory
170597mdn2002Igra (COCI17_igra)C++14
100 / 100
2 ms376 KiB
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int n,c[4],d[4];
string a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("lemonade.in","r",stdin);
    //freopen("lemonade.out","w",stdout);
    cin>>n>>a>>b;
    for(int i=0; i<n; i++)c[a[i]-'a']++;
    for(int i=0; i<n; i++)d[b[i]-'a']++;
    for(int i=0; i<n; i++)
    {
        d[b[i]-'a']--;
        for(int j=0; j<3; j++)
        {
            if(b[i]-'a'==j)continue;
            if(j==0&&c[0])
            {
                if(c[1]+c[2]>=d[0]&&c[0]+c[2]-1>=d[1]&&c[0]+c[1]-1>=d[2])
                {
                    cout<<'a';
                    c[0]--;
                    break;
                }
            }
            if(j==1&&c[1])
            {
                if(c[1]+c[2]-1>=d[0]&&c[0]+c[2]>=d[1]&&c[0]+c[1]-1>=d[2])
                {
                    cout<<'b';
                    c[1]--;
                    break;
                }
            }
            if(j==2&&c[2])
            {
                if(c[1]+c[2]-1>=d[0]&&c[0]+c[2]-1>=d[1]&&c[0]+c[1]>=d[2])
                {
                    cout<<'c';
                    c[2]--;
                    break;
                }
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...