Submission #211920

#TimeUsernameProblemLanguageResultExecution timeMemory
211920WLZBuilding 4 (JOI20_building4)C++14
100 / 100
469 ms121776 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; const int INF = 0x3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector< vector<int> > a(2, vector<int>(2 * n + 1)); for (int i = 0; i < 2; i++) { for (int j = 1; j <= 2 * n; j++) { cin >> a[i][j]; } } vector< vector<int> > dp_r(2 * n + 1, vector<int>(2, -1)); vector< vector<int> > dp_l(2 * n + 1, vector<int>(2, INF)); dp_r[0][0] = dp_r[0][1] = dp_l[0][0] = dp_l[0][1] = 0; for (int i = 0; i < 2 * n; i++) { for (int j = 0; j < 2; j++) { if (dp_r[i][j] == -1) { continue; } if (a[j][i] <= a[0][i + 1]) { dp_r[i + 1][0] = max(dp_r[i + 1][0], dp_r[i][j] + 1); dp_l[i + 1][0] = min(dp_l[i + 1][0], dp_l[i][j] + 1); } if (a[j][i] <= a[1][i + 1]) { dp_r[i + 1][1] = max(dp_r[i + 1][1], dp_r[i][j]); dp_l[i + 1][1] = min(dp_l[i + 1][1], dp_l[i][j]); } } } int cur; if (dp_r[2 * n][0] >= n && dp_l[2 * n][0] <= n) { cur = 0; } else if (dp_r[2 * n][1] >= n && dp_l[2 * n][1] <= n) { cur = 1; } else { cout << -1 << '\n'; return 0; } string ans = ""; for (int i = 2 * n, cnt = n; i >= 1; i--) { if (cur == 0) { ans += 'A'; cnt--; } else { ans += 'B'; } if (a[0][i - 1] <= a[cur][i] && dp_r[i - 1][0] >= cnt && dp_l[i - 1][0] <= cnt) { cur = 0; } else { cur = 1; } } reverse(ans.begin(), ans.end()); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...