제출 #224103

#제출 시각아이디문제언어결과실행 시간메모리
224103Minnakhmetov건물 4 (JOI20_building4)C++14
11 / 100
1916 ms127936 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(aaa) aaa.begin(), aaa.end() const int N = 4005; int dp[N][N], a[2][N], ans[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 0; i < 2; i++) { for (int j = 0; j < n + n; j++) { cin >> a[i][j]; } } memset(dp, -1, sizeof(dp)); dp[1][0] = 0; dp[1][1] = 1; for (int i = 1; i < n + n; i++) { for (int j = 0; j <= n; j++) { if (dp[i][j] != -1) { for (int k = 0; k <= min(1, n - j); k++) { if (a[dp[i][j]][i - 1] <= a[k][i]) { if (dp[i + 1][j + k] == -1 || a[dp[i + 1][j + k]][i] > a[k][i]) { dp[i + 1][j + k] = k; } } } } } } // cout << dp[1][0] << "\n"; if (dp[n + n][n] == -1) { cout << "-1"; } else { int x = n + n, y = n; while (x > 0) { ans[x - 1] = dp[x][y]; y -= dp[x][y]; x--; } for (int i = 0; i < n + n; i++) { cout << (ans[i] ? 'B' : 'A'); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...