Submission #970803

#TimeUsernameProblemLanguageResultExecution timeMemory
970803AiperiiiBuilding 4 (JOI20_building4)C++14
0 / 100
288 ms524288 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]; vector <int> pr[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]; pr[i][j][0]={i-1,j,0}; } if(a[i]>=b[i-1] && !dp[i][j][0]){ dp[i][j][0]=dp[i-1][j][1]; pr[i][j][0]={i-1,j,1}; } if(j-1>=0){ if(b[i]>=a[i-1]){ dp[i][j][1]=dp[i-1][j-1][0]; pr[i][j][1]={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]; pr[i][j][1]={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'; else res+='A'; vector <int> v=pr[x][y][z]; x=v[0]; y=v[1]; z=v[2]; } 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...