Submission #249484

# Submission time Handle Problem Language Result Execution time Memory
249484 2020-07-15T06:30:24 Z VEGAnn Igra (COCI17_igra) C++14
100 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
int cnt[3], ost[3], n;
string s;

bool ok(){
    for (int msk = 1; msk < (1 << 3); msk++){
        int sm = 0, nmsk = 0;

        for (int i = 0; i < 3; i++)
            if (msk & (1 << i)){
                sm += cnt[i];
                nmsk |= (7 - (1 << i));
            }

        int kol = 0;

        for (int i = 0; i < 3; i++)
            if (nmsk & (1 << i))
                kol += ost[i];

        if (kol < sm) return 0;
    }

    return 1;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 0; i < n; i++){
        char c; cin >> c;

        cnt[c - 'a']++;
    }

    cin >> s;

    for (int i = 0; i < n; i++){
        ost[s[i] - 'a']++;
    }

    for (int i = 0; i < n; i++){
        int tp = 0, ch = (s[i] - 'a');

        for (;; tp++){
            if (tp == ch) continue;

            cnt[tp]--;
            ost[ch]--;

            if (ok()) {
                cout << char(tp + 'a');
                break;
            } else {
                cnt[tp]++;
                ost[ch]++;
            }
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct