# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963287 | shezitt | Igra (COCI17_igra) | C++14 | 2 ms | 348 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 <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <queue>
#include <numeric>
using namespace std;
using ll = long long;
#define int ll
#define fore(i, a, b) for(int i=a; i<b; ++i)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s, m, ans;
cin >> s >> m;
int scnt[3] = {};
int mcnt[3] = {};
int stmp[3] = {};
for(char c : s){
scnt[c - 'a']++;
}
for(char c : m){
mcnt[c - 'a']++;
}
auto check = [&](int i, int p) -> bool {
fore(j, 0, 3){
stmp[j] = scnt[j];
}
if(stmp[p] == 0) return 0;
if(m[i] == 'a'+p) {
return 0;
}
stmp[p]--;
int ba, bc, ac, ab, ca, cb;
fore(bba, 0, stmp[1]+1){
ba = bba;
bc = stmp[1] - ba;
ac = mcnt[2] - bc;
ca = mcnt[0] - ba;
ab = stmp[0] - ac;
cb = stmp[2] - ca;
bool ok = min({ba, bc, ac, ca, ab, cb}) >= 0;
ok &= ac + ab == stmp[0] && ba + bc == stmp[1] && ca + cb == stmp[2];
if(ok){
return 1;
}
}
return 0;
};
fore(i, 0, n){
mcnt[m[i] - 'a']--;
fore(j, 0, 3){
if(check(i, j)){
scnt[j]--;
ans.pb('a'+j);
break;
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |