# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
930821 | ksujay2 | Building 4 (JOI20_building4) | C++17 | 0 ms | 0 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.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FOR(i, b) for(int i = 0; i < (b); i++)
#define ROF(i, b) for(int i = (b) - 1; i >= 0; i--)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); i--)
using pi = pair<int, int>;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int N; cin >> N;
vector<int> A(2 * N), B(2 * N);
FOR(i, 2 * N) cin >> A[i];
FOR(i, 2 * N) cin >> B[i];
vector<array<int, 2>> dp(2 * N, {{-1, -1}});
dp[0][0] = -2;
dp[0][1] = -2;
FOR(i, 1, 2 * N) {
if(dp[i - 1][0] != -1) {
if(A[i - 1] <= A[i]) {
dp[i][0] = 0;
}
if(A[i - 1] <= B[i]) {
dp[i][1] = 0;
}
}
if(dp[i - 1][1] != -1) {
if(B[i - 1] <= A[i]) {
dp[i][0] = 1;
}
if(B[i - 1] <= B[i]) {
dp[i][1] = 1;
}
}
}
if(dp.back()[0] != -1) {
vector<int> choice(2 * N);
choice[2 * N - 1] = 0;
ROF(i, 2 * N, 1) {
choice[i - 1] = dp[i][choice[i]];
}
FOR(i, 2 * N) {
if(choice[i] == 0) cout << 'A';
else cout << 'B';
}
} else if(dp.back()[1] != -1) {
vector<int> choice(2 * N);
choice[2 * N - 1] = 1;
ROF(i, 2 * N, 1) {
choice[i - 1] = dp[i][choice[i]];
}
FOR(i, 2 * N) {
if(choice[i] == 0) cout << 'A';
else cout << 'B';
}
} else {
cout << -1 << endl;
}
}