#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |