Submission #477388

#TimeUsernameProblemLanguageResultExecution timeMemory
477388largefenceIgra (COCI17_igra)C++17
20 / 100
1 ms336 KiB
#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 k = 0; k < 3 && chk; k++) { int tmp = 0; for (int k2 = 0; k2 < 3; k2++) if (k != k2) tmp += cnt[k2] - (k2 == j); if (mp[i + 1][k] > tmp) chk = false; } if (chk) { res += (j + 'a'); cnt[j]--; } } } cout << res; return 0; } /* In case of emergency, ___ _____ _____ _ _ ___ / __|_ _\ \ / / __| | | | | _ \ | (_ || | \ V /| _| | |_| | _/ \___|___| \_/ |___| \___/|_| */
#Verdict Execution timeMemoryGrader output
Fetching results...