# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
490340 | niloyroot | Igra (COCI17_igra) | C++14 | 1 ms | 460 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;
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'||c[j]<=0){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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |