Submission #1114917

#TimeUsernameProblemLanguageResultExecution timeMemory
1114917Younis_DwaiBuilding 4 (JOI20_building4)C++14
0 / 100
10 ms8784 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #define endl "\n" #define F first #define S second #define pb push_back //#define int long long #define in insert #define mid (l+r)/2 #define in insert using namespace std; const int N=2e3+5; bool dp[2*N][N][2]; int b[N],a[N],n; //string ans=""; void get(int id ,int done ,int cur){ if(id==0) return ; if(cur==0){ if(dp[id-1][done-1][0] && a[id-1]<=a[id]) get(id-1,done-1,0); else get(id-1,done-1,1); cout<<'A'; } else{ if(dp[id-1][done][0] && a[id-1]<=b[id]) get(id-1,done,0); else get(id-1,done,1); cout<<'B'; } return ; } int32_t main(){ ios::sync_with_stdio(false);cin.tie(nullptr); 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<=2*n;i++){ for(int j=0;j<=n;j++){ if(dp[i-1][j][0]){ if(a[i-1]<=a[i]) dp[i][j+1][0]=1; if(a[i-1]<=b[i]) dp[i][j][1]=1; } if(dp[i-1][j][1]){ if(b[i-1]<=a[i]) dp[i][j+1][0]=1; if(b[i-1]<=b[i]) dp[i][j][1]=1; } } } if(dp[2*n][n][0]+dp[2*n][n][1]==0) cout<<-1; else{ if(dp[2*n][n][0]==1) get(2*n,n,0); else get(2*n,n,1); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...