# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227423 | anonymous | Building 4 (JOI20_building4) | C++14 | 484 ms | 44024 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 <iostream>
#define MAXN 1000005
using namespace std;
int N, A[MAXN][2];
int dp[MAXN][2][2], Num;
bool res[MAXN], b;
bool can(int i, int j, int v) {return(v >= dp[i][j][0] && v <= dp[i][j][1]);}
int main() {
//freopen("b4in.txt","r",stdin);
scanf("%d",&N);
for (int i=1; i<=2*N; i++) {
scanf("%d", &A[i][0]);
}
for (int i=1; i<=2*N; i++) {
scanf("%d", &A[i][1]);
}
dp[1][1][0] = dp[1][1][1] = 1;
for (int i=2; i<=2*N; i++) {
for (int j=0; j<=1; j++) {
dp[i][j][0] = 1<<30, dp[i][j][1]=-1<<30;
if (A[i][j] >= A[i-1][0]) {
dp[i][j][0] = min(dp[i][j][0], dp[i-1][0][0]+(j > 0));
dp[i][j][1] = max(dp[i][j][1], dp[i-1][0][1]+(j > 0));
}
if (A[i][j] >= A[i-1][1]) {
dp[i][j][0] = min(dp[i][j][0], dp[i-1][1][0]+(j > 0));
dp[i][j][1] = max(dp[i][j][1], dp[i-1][1][1]+(j > 0));
}
}
}
if (!can(2*N, 0, N) && !can(2*N, 1, N)) {
printf("-1");
} else {
b = can(2*N, 1, N), Num = N;
for (int i=2*N; i>=1; i--) {
res[i] = b;
Num -= b;
b = (A[i-1][1] <= A[i][b]) && can(i-1, 1, Num);
}
for (int i=1; i<=2*N; i++) {
printf("%c", res[i] ? 'B' : 'A');
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |