# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
535522 | 79brue | 건물 4 (JOI20_building4) | C++14 | 280 ms | 61204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[1000002][2];
int DP[1000002][2][2]; /// a/b, l/r
int track[1000002][2][2];
int main(){
scanf("%d", &n);
for(int i=1; i<=n+n; i++) scanf("%d", &a[i][0]);
for(int i=1; i<=n+n; i++) scanf("%d", &a[i][1]);
for(int i=1; i<=n+n; i++){
DP[i][0][0] = DP[i][1][0] = 1e9;
for(int j=0; j<2; j++){
for(int j2=0; j2<2; j2++){
if(a[i-1][j2] <= a[i][j]){
if(DP[i][j][0] > DP[i-1][j2][0] + (j==0)){
DP[i][j][0] = DP[i-1][j2][0] + (j==0);
track[i][j][0] = j2;
}
if(DP[i][j][1] < DP[i-1][j2][1] + (j==0)){
DP[i][j][1] = DP[i-1][j2][1] + (j==0);
track[i][j][1] = j2;
}
}
}
}
}
int i=0, j=0;
if((DP[n+n][0][0] <= n && n <= DP[n+n][0][1])) i=n+n, j=0;
else if(DP[n+n][1][0] <= n && n <= DP[n+n][1][1]) i=n+n, j=1;
else{
puts("-1");
return 0;
}
string s;
int cnt = n;
while(i){
if(j==0) s.push_back('A'), cnt--;
else s.push_back('B');
int c = 0;
if(a[i][j] < a[i-1][0]) c = 1;
else if(DP[i-1][0][0] > cnt || DP[i-1][0][1] < cnt) c = 1;
j = c;
i--;
}
reverse(s.begin(), s.end());
printf("%s", s.c_str());
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |