# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
310855 | kaplanbar | Igra (COCI17_igra) | C++14 | 1 ms | 384 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;
using ll = long long;
int c[3], dp[5005][3];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string a, b;
cin >> a >> b;
for(int i = 0; i < n; i++) {
c[a[i] - 'a']++;
}
for(int i = n - 1; i >= 0; i--) {
dp[i][b[i] - 'a']++;
if(i != n - 1) {
for(int j = 0; j < 3; j++) dp[i][j] += dp[i + 1][j];
}
}
auto check = [&](int idx) -> bool {
if(idx == n - 1) return true;
int s = 0;
for(int i = 0; i < 3; i++) {
s += c[i];
}
for(int i = 0; i < 3; i++) {
if(s - c[i] < dp[idx + 1][i]) return false;
}
return true;
};
for(int i = 0; i < n; i++) {
for(int j = 0; j < 3; j++) {
if(c[j] && j != b[i] - 'a') {
c[j]--;
if(check(i)) {
cout << (char)(j + 'a');
break;
}
c[j]++;
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |