Submission #424554

#TimeUsernameProblemLanguageResultExecution timeMemory
424554tengiz05Building 4 (JOI20_building4)C++17
11 / 100
481 ms524292 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...