# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300146 | BeanZ | Building 4 (JOI20_building4) | C++14 | 73 ms | 21240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I_LOVE_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 5e5 + 5;
const int lim = 3e2;
ll inf = 1e18;
ll a[N][2], vis[N][2];
pair<ll, ll> dp[N][2]; // dem B
void DP(ll i, ll j){
if (vis[i][j]) return;
vis[i][j] = 1;
ll mn = inf, mx = -inf;
if (a[i][j] <= a[i + 1][0]){
DP(i + 1, 0);
mn = min(mn, dp[i + 1][0].first);
mx = max(mx, dp[i + 1][0].second);
}
if (a[i][j] <= a[i + 1][1]){
DP(i + 1, 1);
mn = min(mn, dp[i + 1][1].first + 1);
mx = max(mx, dp[i + 1][1].second + 1);
}
dp[i][j] = {mn, mx};
//cout << dp[i][j].first << " " << dp[i][j].second << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin >> n;
n *= 2;
for (int j = 0; j < 2; j++){
for (int i = 1; i <= n; i++){
cin >> a[i][j];
}
}
vis[n][0] = vis[n][1] = 1;
DP(0, 0);
if (dp[0][0].first > (n / 2) || dp[0][0].second < (n / 2)) return cout << -1, 0;
ll cur = n / 2;
ll last = 0;
for (int i = 1; i <= n; i++){
//cout << dp[i][1].first << " " << dp[i][1].second << endl;
if (a[i][1] >= a[i - 1][last] && dp[i][1].first <= (cur - 1) && (cur - 1) <= dp[i][1].second){
cout << "B";
last = 1;
cur--;
} else {
cout << "A";
last = 0;
}
}
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |