#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3PGDklf ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
signed main(){
_3PGDklf;
int n;
cin>>n;
auto stovi=[&](string s)->vi{
vi tmp;
for(auto c:s){
tmp.pb(c-'a');
}
return tmp;
};
string s;
cin>>s;
vi a=stovi(s);
cin>>s;
vi b=stovi(s);
const int m=3;
vi cnta(m),cntb(m);
rep(i,n){
cnta[a[i]]+=1;
cntb[b[i]]+=1;
}
string pns="";
rep(i,n){
int ch=b[i];
cntb[ch]-=1;
rep(j,m){
if(ch==j or !cnta[j]) continue;
cnta[j]-=1;
bool gok=0;
rep(x,cnta[0]+1){
bool pok=1;
vi nowa=cnta,nowb=cntb;
if(nowb[1]>=x){
// a->b
nowa[0]-=x;
nowb[1]-=x;
// a->c
nowb[2]-=nowa[0];
nowa[0]=0;
// c->b
nowa[2]-=nowb[1];
nowb[1]=0;
// b->c
nowa[1]-=nowb[2];
nowb[1]=0;
// b->a and c->a
nowb[0]-=(nowa[1]+nowa[2]);
nowa[1]=0;
nowa[2]=0;
rep(v,m){
if(nowa[v]!=0 or nowb[v]!=0){
pok=0;
}
}
}
if(pok){
gok=1;
break;
}
}
// if(i==0) print("go",j);
if(gok){
pns+=(char)('a'+j);
break;
}
cnta[j]+=1;
}
// break;
}
print(pns);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
324 KB |
Output isn't correct |
9 |
Incorrect |
169 ms |
396 KB |
Output isn't correct |
10 |
Incorrect |
193 ms |
340 KB |
Output isn't correct |