Submission #486477

# Submission time Handle Problem Language Result Execution time Memory
486477 2021-11-11T18:49:01 Z perchuts Igra (COCI17_igra) C++17
40 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf (int)(2e9+1)
#define mod (int)(1e9+7)

using namespace std;
int n,q[3];
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string in,m,ans="";
    cin>>n>>in>>m;
    
    for(int i=0;i<n;i++)
        q[in[i]-'a']++;

    for(int i=0;i<n;i++){
        int x,y,z;
        if(m[i]=='a'){
            x=0,y=1,z=2;
        }else if(m[i]=='b'){
            x=1,y=0,z=2;
        }else{
            x=2,y=0,z=1;
        }
        if(q[y]){
            q[y]--;ans+=char('a'+y);
        }else{
            if(q[z]){
                q[z]--;ans+=char('a'+z);
            }else{
                for(int j=i-1;j>=0;j--){
                    if(ans[j]!=m[i]&&m[j]!=m[i]){
                        ans+=ans[j];
                        ans[j]=m[i];
                        q[x]--;
                        break;
                    }
                }
            }
        }
        // cout<<ans<<endl;
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Incorrect 0 ms 204 KB Output isn't correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Incorrect 1 ms 332 KB Output isn't correct