Submission #752129

#TimeUsernameProblemLanguageResultExecution timeMemory
752129sofija6Building 4 (JOI20_building4)C++14
11 / 100
2086 ms23396 KiB
#include <bits/stdc++.h> #define ll int #define MAXN 1000010 #define llinf 1e9 using namespace std; ll a[2][MAXN],dp[2][MAXN][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i=0;i<2;i++) { for (ll j=1;j<=2*n;j++) cin >> a[i][j]; } dp[0][1][0]=dp[0][1][1]=1; dp[1][1][0]=dp[1][1][1]=0; for (ll i=2;i<=2*n;i++) { dp[0][i][0]=dp[1][i][0]=llinf; dp[0][i][1]=dp[1][i][1]=-llinf; for (ll j=0;j<2;j++) { if (a[0][i]>=a[j][i-1]) { dp[0][i][0]=min(dp[0][i][0],dp[j][i-1][0]+1); dp[0][i][1]=max(dp[0][i][1],dp[j][i-1][1]+1); } if (a[1][i]>=a[j][i-1]) { dp[1][i][0]=min(dp[1][i][0],dp[j][i-1][0]); dp[1][i][1]=max(dp[1][i][1],dp[j][i-1][1]); } } } if ((dp[0][2*n][0]>n || dp[0][2*n][1]<n) && (dp[1][2*n][0]>n || dp[1][2*n][1]<n)) { cout << -1; return 0; } ll val=n,pos=2*n+1,i=1; a[0][pos]=a[1][pos]=llinf; string ans=""; while (pos>1) { val-=(1-i); i=dp[0][pos-1][0]<=val && dp[0][pos-1][1]>=val && a[0][pos-1]<=a[i][pos]?0 : 1; ans=(i?"B" : "A")+ans; pos--; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...