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>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(2 * n), b(2 * n);
for (int i = 0; i < 2 * n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < 2 * n; i++) {
std::cin >> b[i];
}
std::vector<std::vector<int>> dp(2 * n + 1, std::vector<int>(n + 1, 2e9));
std::vector<std::vector<int>> par(2 * n + 1, std::vector<int>(n + 1, 0));
dp[0][0] = 0;
for (int i = 1; i <= 2 * n; i++) {
for (int j = 0; j <= n; j++) {
if (j && a[i - 1] >= dp[i - 1][j - 1]) {
if (dp[i][j] > a[i - 1]) {
dp[i][j] = a[i - 1];
par[i][j] = -1;
}
}
if (b[i - 1] >= dp[i - 1][j]) {
if (dp[i][j] > b[i - 1]) {
dp[i][j] = b[i - 1];
par[i][j] = 0;
}
}
}
}
if (dp[2 * n][n] < 2e9) {
int i = 2 * n, j = n;
std::string ans;
while (i > 0) {
if (par[i][j] == -1) {
ans += 'A';
j--;
} else {
ans += 'B';
}
i--;
}
reverse(ans.begin(), ans.end());
std::cout << ans << "\n";
} else {
std::cout << -1 << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |