Submission #476175

# Submission time Handle Problem Language Result Execution time Memory
476175 2021-09-25T07:42:58 Z 2548631 Igra (COCI17_igra) C++17
100 / 100
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL)
#define forw(i, l, r) for( int i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( int i = (r) ; i >= (l) ; i-- )
#define log2i(x) (64 - __builtin_clzll(1ll * (x)) - 1)
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define Pi acos(-1.0l)
#define sz(x) int(x.size())
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(x) cerr << #x << " = " << x << '\n';

int n;
int cnt[2][3];
string a, b, ans;

bool chk(int choose) {
    int val[3] = {cnt[0][0], cnt[0][1], cnt[0][2]};
    val[choose]--;
    if(val[choose] < 0) return false;
    if(val[0] + val[2] >= cnt[1][1] &&
       val[0] <= cnt[1][1] + cnt[1][2] &&
       val[2] <= cnt[1][0] + cnt[1][1]) return true;
    return false;
}

int main() {
    fastIO;
#ifndef ONLINE_JUDGE
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
#endif

    cin >> n >> a >> b;
    forw(i, 0, n) {
        cnt[0][a[i] - 'a']++;
        cnt[1][b[i] - 'a']++;
    }

    forw(i, 0, n) {
        cnt[1][b[i] - 'a']--;
        forw(j, 0, 3) if(b[i] - 'a' != j && chk(j)) {
            ans += char(j + 'a');
            cnt[0][j]--;
            break;
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 272 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct