| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 487615 | KazamaHoang | Igra (COCI17_igra) | C++14 | 1 ms | 336 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;
int n;
string s, t;
int cnt[3], suf[3][50005];
bool put(int x, int u) {
    if (t[u] == x || cnt[x] == 0) return false;
    -- cnt[x];
    int sumcnt = 0;
    for (int i = 0; i < 3; ++ i) sumcnt += cnt[i];
    for (int i = 0; i < 3; ++ i) {
        int rem = sumcnt - cnt[i];
        int tmp = suf[i][u+1];
        if (rem < tmp) {
            ++ cnt[x];
            return false;
        }
    }
    return true;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> s >> t;
    s = " " + s;
    t = " " + t;
    for (int i = n; i >= 1; -- i) {
        s[i] -= 'a';
        t[i] -= 'a';
        ++ cnt[s[i]];
        for (int j = 0; j < 3; ++ j) 
            suf[j][i] = suf[j][i+1] + (t[i] == j);
    }
    string res = "";
    for (int i = 1; i <= n; ++ i) {
        for (int j = 0; j < 3; ++ j) 
            if (put(j, i)) {
                res += char('a' + j);
                break;
            }
    }
    cout << res;
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
