제출 #1225402

#제출 시각아이디문제언어결과실행 시간메모리
1225402Double_Slash건물 4 (JOI20_building4)C++20
0 / 100
5 ms332 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n <<= 1][2]; for (int i = 0; i < n; ++i) cin >> a[i][0]; for (int i = 0; i < n; ++i) cin >> a[i][1]; auto dp = [&] (int a[][2]) { auto dp = new int[n][2]{{1, -1}}; for (int i = 0; ++i < n;) { for (int x = 2; x--;) dp[i][x] = max( a[i][x] >= a[i - 1][0] ? dp[i - 1][0] : -n, a[i][x] >= a[i - 1][1] ? dp[i - 1][1] : -n) + not x - x; } for (int i = n; i--;) swap(a[i][0], a[i][1]); return dp; }; auto top = dp(a), bot = dp(a); if (min(max(top[n - 1][0], top[n - 1][1]), max(bot[n - 1][0], bot[n - 1][1])) < 0) { cout << "-1\n"; return 0; } bool ans[n]; for (int i = n, sum = 0; i--;) { if (i) { ans[i] = (i == n - 1 or a[i][1] <= a[i + 1][ans[i + 1]]) and top[i][1] + sum >= 0; sum += not ans[i] - ans[i]; } else ans[i] = sum > 0; } for (bool b: ans) cout << (char) ('A' + b); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...