# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
228341 | wilwxk | Building 4 (JOI20_building4) | C++14 | 117 ms | 13432 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5+5;
int h[MAXN][2];
int dp[MAXN][2][2];
int ans[MAXN];
int n;
int main() {
scanf("%d", &n);
for(int i = 1; i <= n*2; i++) scanf("%d", &h[i][0]);
for(int i = 1; i <= n*2; i++) scanf("%d", &h[i][1]);
for(int i = 1; i <= n*2; i++) {
for(int b = 0; b < 2; b++) {
dp[i][b][0] = MAXN;
dp[i][b][1] = -MAXN;
for(int a = 0; a < 2; a++) {
if(h[i-1][a] > h[i][b]) continue;
dp[i][b][0] = min(dp[i][b][0], dp[i-1][a][0]+b);
dp[i][b][1] = max(dp[i][b][1], dp[i-1][a][1]+b);
}
}
// printf("%d > %d %d\n", i, dp[i][0][0], dp[i][0][1]);
// printf("%d > %d %d\n", i, dp[i][1][0], dp[i][1][1]);
}
h[n*2+1][0] = h[n*2+1][1] = 1e9+9;
int cnt = 0; int last = 0;
for(int i = n*2; i >= 1; i--) {
if(h[i][0] <= h[i+1][last]) {
if(dp[i][0][0] <= n-cnt && dp[i][0][1] >= n-cnt) {
ans[i] = 0;
last = 0;
continue;
}
}
if(h[i][1] <= h[i+1][last]) {
if(dp[i][1][0] <= n-cnt && dp[i][1][1] >= n-cnt) {
ans[i] = 1;
cnt++;
last = 1;
continue;
}
}
printf("-1\n");
return 0;
}
for(int i = 1; i <= n*2; i++) printf("%c", 'A'+ans[i]);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |