Submission #487615

# Submission time Handle Problem Language Result Execution time Memory
487615 2021-11-16T09:38:28 Z KazamaHoang Igra (COCI17_igra) C++14
100 / 100
1 ms 336 KB
#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

igra.cpp: In function 'int main()':
igra.cpp:33:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   33 |         ++ cnt[s[i]];
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct