Submission #490336

#TimeUsernameProblemLanguageResultExecution timeMemory
490336niloyrootIgra (COCI17_igra)C++14
30 / 100
1 ms460 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<ll>; using pl = pair<ll,ll>; #define pb push_back #define form(m,it) for(auto it=m.begin(); it!=m.end(); it++) #define forp(i,a,b) for(ll i=a; i<=b; i++) #define forn(i,a,b) for(ll i=a; i>=b; i--) #define newl '\n' #define ff first #define ss second const ll mod = 1000000007; void solve(){ ll n; cin>>n; string a,b; cin>>a>>b; ll c[3]={0}; forp(i,0,n-1){c[a[i]-'a']++;} ll cnt[3][n+1]; memset(cnt,0,sizeof(cnt)); forn(i,n-1,0){ forp(j,0,2){ cnt[j][i]=cnt[j][i+1]+(b[i]-'a'==j); } } string s=""; bool g; ll sum; forp(i,0,n-1){ forp(j,0,2){ g=1; if(j==b[i]-'a'){continue;} forp(k,0,2){ sum=0; forp(m,0,2){ if(m!=k){ sum+=c[m]; if(m==j){sum--;} } } if(sum<cnt[k][i+1]){ g=0; } } if(g){ c[j]--; s+=(j+'a'); break; } } } cout<<s<<newl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; //cin>>t; while(t--)solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...