제출 #682050

#제출 시각아이디문제언어결과실행 시간메모리
682050Kahou건물 4 (JOI20_building4)C++14
100 / 100
220 ms24864 KiB
/* In the name of God, aka Allah */ // let this be mytemp.cpp #include<bits/stdc++.h> using namespace std; #define F first #define S second #define endl '\n' #define mk make_pair typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 2e6 + 50; int n, a[N]; pii dp[N]; void solve() { cin >> n; n <<= 1; for (int i = 1; i <= n; i++) { cin >> a[i<<1]; } for (int i = 1; i <= n; i++) { cin >> a[i<<1|1]; } dp[n<<1] = {0, 0}; dp[n<<1|1] = {1, 1}; for (int i = (n<<1)-1; i >= 0; i--) { dp[i] = {N, -N}; int x = i+2, y = x^1; if (a[i] <= a[x]) { dp[i].F = min(dp[i].F, dp[x].F+(i&1)); dp[i].S = max(dp[i].S, dp[x].S+(i&1)); } if (a[i] <= a[y]) { dp[i].F = min(dp[i].F, dp[y].F+(i&1)); dp[i].S = max(dp[i].S, dp[y].S+(i&1)); } } if (dp[0].F > n/2 || dp[0].S < n/2) return cout << -1 << endl, void(); int cur = n/2; int u = 0; for (int x = 1; x <= n; x++) { if (a[u] <= a[x<<1] && dp[x<<1].F <= cur && cur <= dp[x<<1].S) { cout << 'A'; u = x<<1; } else { cout << 'B'; u = x<<1|1; cur--; } } cout << endl; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...