# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
639675 |
2022-09-11T02:21:02 Z |
classic |
Igra (COCI17_igra) |
C++14 |
|
1 ms |
596 KB |
#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 |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
584 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |