# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
639675 | classic | Igra (COCI17_igra) | C++14 | 1 ms | 596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |