# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
371245 | FatihSolak | Igra (COCI17_igra) | C++17 | 1 ms | 492 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>
#define N 5005
using namespace std;
int cnt[3];
int suf[N][3];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
cin >> n;
string s,t;
cin >> s >> t;
for(int i=n-1;i>=0;i--){
for(int j=0;j<3;j++){
suf[i][j] = suf[i+1][j] + ((t[i]-'a') == j);
}
cnt[s[i]-'a']++;
}
string ans;
for(int i=0;i<n;i++){
for(int j=0;j<3;j++){
bool ok = 1;
for(int c=0;c<3;c++){
int sum = 0;
for(int d=0;d<3;d++){
if(d != c)sum+=cnt[d] - (d == j);
}
if(suf[i+1][c] > sum){
ok = 0;
}
}
if(cnt[j] && (t[i]-'a') != j && ok){
ans+='a'+j;
cnt[j]--;
break;
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |