Submission #477389

# Submission time Handle Problem Language Result Execution time Memory
477389 2021-10-02T01:30:16 Z largefence Igra (COCI17_igra) C++17
100 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

int cnt[3], mp[5243][4];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("ws.INP", "r", stdin);
    //freopen("ws.OUT", "w", stdout);

    memset(cnt, 0, sizeof cnt);
    memset(mp, 0, sizeof mp);
    int n; cin >> n;
    string a, b; cin >> a >> b;
    for (int i = n - 1; i >= 0; i--) {
        cnt[a[i] - 'a']++;
        for (int j = 0; j < 3; j++)
            mp[i][j] = mp[i + 1][j] + ((b[i] - 'a') == j);
    } string res = "";
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            if (!cnt[j] || (b[i] - 'a') == j) continue;
            bool chk = true;
            for (int c = 0; c < 3 && chk; c++) {
                int tmp = 0;
                for (int d = 0; d < 3; d++)
                    if (c != d) tmp += cnt[d] - (d == j);
                if (mp[i + 1][c] > tmp) chk = false;
            }
            if (chk) {
                res += (j + 'a');
                cnt[j]--;
                break;
            }
        }
    } cout << res;
    return 0;
}
/* In case of emergency,
   ___ _____   _____   _   _ ___
  / __|_ _\ \ / / __| | | | | _ \
 | (_ || | \ V /| _|  | |_| |  _/
  \___|___| \_/ |___|  \___/|_|

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct