제출 #568611

#제출 시각아이디문제언어결과실행 시간메모리
568611losmi247건물 4 (JOI20_building4)C++14
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2002; int n,a[N],b[N]; int dp[N][N][2]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= 2*n; i++){ cin >> a[i]; } for(int i = 1; i <= 2*n; i++){ cin >> b[i]; } dp[0][0][0] = dp[0][0][1] = 1; for(int i = 1; i <= 2*n; i++){ for(int j = 0; j <= n; j++){ if(j > 0 && a[i] >= a[i-1]) dp[i][j][0] |= dp[i-1][j-1][0]; if(j > 0 && a[i] >= b[i-1]) dp[i][j][0] |= dp[i-1][j-1][1]; if(b[i] >= a[i-1]) dp[i][j][1] |= dp[i-1][j][0]; if(b[i] >= b[i-1]) dp[i][j][1] |= dp[i-1][j][1]; } } int x = 2*n,y = n,z = 0; if(dp[x][y][z] == 0) z = 1; if(dp[x][y][z] == 0){ cout << -1 << endl; return 0; } string s = ""; while(x){ if(z == 0){ assert(y > 0); s += "A"; if(a[x] >= a[x-1] && dp[x-1][y-1][0]){ x--; y--; z = 0; } else{ assert(a[x] >= b[x-1] && dp[x-1][y-1][1]); x--; y--; z = 1; } } else{ s += "B"; if(b[x] >= a[x-1] && dp[x-1][y][0]){ x--; z = 0; } else{ assert(b[x] >= b[x-1] && dp[x-1][y][1]); x--; z = 1; } } } reverse(s.begin(),s.end()); cout << s << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...