Submission #970801

#TimeUsernameProblemLanguageResultExecution timeMemory
970801AiperiiiBuilding 4 (JOI20_building4)C++14
0 / 100
283 ms383480 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],b[N],dp[N][N][2]; vector <int> pr[N][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<=i;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...