# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
212806 | GioChkhaidze | Building 4 (JOI20_building4) | C++14 | 398 ms | 36204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N=2e6+6;
int n,a[N],b[N],dp[N][2][2];
main () {
ios::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
scanf("%d",&n); n*=2;
for (int i=1; i<=n; i++)
scanf("%d",&a[i]);
for (int i=1; i<=n; i++)
scanf("%d",&b[i]);
for (int i=0; i<=n; i++) {
dp[i][0][0]=1e9;
dp[i][0][1]=-1e9;
dp[i][1][0]=1e9;
dp[i][1][1]=-1e9;
}
dp[0][0][0]=0;
dp[0][0][1]=0;
dp[0][1][0]=0;
dp[0][1][1]=0;
for (int i=1; i<=n; i++) {
if (a[i-1]<=a[i]) {
dp[i][0][0]=min(dp[i][0][0],dp[i-1][0][0]+1);
dp[i][0][1]=max(dp[i][0][1],dp[i-1][0][1]+1);
}
if (a[i-1]<=b[i]) {
dp[i][1][0]=min(dp[i][1][0],dp[i-1][0][0]-1);
dp[i][1][1]=max(dp[i][1][1],dp[i-1][0][1]-1);
}
if (b[i-1]<=a[i]) {
dp[i][0][0]=min(dp[i][0][0],dp[i-1][1][0]+1);
dp[i][0][1]=max(dp[i][0][1],dp[i-1][1][1]+1);
}
if (b[i-1]<=b[i]) {
dp[i][1][0]=min(dp[i][1][0],dp[i-1][1][0]-1);
dp[i][1][1]=max(dp[i][1][1],dp[i-1][1][1]-1);
}
}
int f=0,l=1e9;
string ans="";
for (int i=n; i>=1; i--) {
if (dp[i][0][0]<=f && f<=dp[i][0][1] && a[i]<=l) {
--f,l=a[i];
ans+='A';
}
else
if (dp[i][1][0]<=f && f<=dp[i][1][1] && b[i]<=l) {
++f,l=b[i];
ans+='B';
}
else {
cout<<-1<<endl;
return 0;
}
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |