제출 #970808

#제출 시각아이디문제언어결과실행 시간메모리
970808Aiperiii건물 4 (JOI20_building4)C++14
11 / 100
56 ms125980 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=2e3+5; int a[N*2],b[N*2],dp[N*2][N][2]; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n; cin>>n; for(int i=1;i<=n*2;i++)cin>>a[i]; for(int i=1;i<=n*2;i++)cin>>b[i]; dp[0][0][0]=1; for(int i=1;i<=n*2;i++){ for(int j=0;j<=min(i,n);j++){ if(a[i]>=a[i-1]){ dp[i][j][0]=dp[i-1][j][0]; } if(a[i]>=b[i-1] && !dp[i][j][0]){ dp[i][j][0]=dp[i-1][j][1]; } if(j-1>=0){ if(b[i]>=a[i-1]){ dp[i][j][1]=dp[i-1][j-1][0]; } if(b[i]>=b[i-1] && !dp[i][j][1]){ dp[i][j][1]=dp[i-1][j-1][1]; } } } } int x=n*2,y=n,z=-1; string res=""; if(dp[n*2][n][1]==1)z=1; if(dp[n*2][n][0]==1)z=0; if(z==-1){ cout<<-1<<"\n"; return 0; } while(x>=1){ if(z==1){ res+='B'; if(b[x]>=a[x-1] && dp[x-1][y-1][0])z=0; else z=1; y--; } else{ if(a[x]>=a[x-1] && dp[x-1][y][0])z=0; else z=1; res+='A'; } x--; } reverse(all(res)); cout<<res<<"\n"; } /* 3 0 9 8 1 13 7 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...