# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
639675 | classic | Igra (COCI17_igra) | C++14 | 1 ms | 596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s, t;
cin >> s >> t;
vector<int> cnt(3);
for (int i = 0; i < n; i++) {
cnt[s[i] - 'a'] += 1;
}
vector<vector<int>> suff(n + 1, vector<int>(3));
suff[n - 1][t[n - 1] - 'a'] += 1;
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j < 3; j++) {
suff[i][j] = suff[i + 1][j];
}
suff[i][t[i] - 'a'] += 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if (j == t[i] - 'a' || cnt[j] <= 0) {
continue;
}
cnt[j] -= 1;
bool ok = true;
for (int x = 0; x < 3; x++) {
for (int y = x + 1; y < 3; y++) {
int z = 3 - x - y;
if (cnt[x] + cnt[y] < suff[i + 1][z]) {
ok = false;
}
if (!ok) {
break;
}
}
if (!ok) {
break;
}
}
if (ok) {
cout << char(j + 'a');
break;
} else {
cnt[j] += 1;
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |