Submission #954669

#TimeUsernameProblemLanguageResultExecution timeMemory
954669edogawa_somethingBuilding 4 (JOI20_building4)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vii; typedef pair<ll,ll> pii; #define F first #define S second #define pb push_back #define eb emplace_back #define all(v) v.begin(),v.end() #define pow poww const ll M=2010; const ll inf=2e9; const ll mod=2e9; ll pow(ll x,ll y){ ll res=1; x%=mod; while(y>0){ if((y&1)) res*=x,res%=mod; x*=x,x%=mod; y=(y>>1); } return res; } ll n,a[M],b[M]; bool dp[M][M][2]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int TC=1; //cin>>TC; while(TC--){ cin>>n; n*=2; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; dp[0][0][0]=dp[0][1][1]=1; for(int i=1;i<n;i++){ if(a[i]>b[i-1]){ for(int j=0;j<=i;j++){ if(dp[i-1][j][0]) dp[i][j+1][1]=1; } } if(a[i]>a[i-1]){ for(int j=0;j<=i;j++){ if(dp[i-1][j][1]) dp[i][j+1][1]=1; } } if(b[i]>b[i-1]){ for(int j=0;j<=i;j++){ if(dp[i-1][j][0]) dp[i][j][0]=1; } } if(b[i]>a[i-1]){ for(int j=0;j<=i;j++){ if(dp[i-1][j][1]) dp[i][j][0]=1; } } } ll cnt=n-1,cur=n/2; string ans; if(!dp[cnt][cur][0]&&!dp[cnt][cur][1]){ cout<<-1; return 0; } bool c=0; if(!dp[cnt][cur][0]) c=1; if(c) ans.pb('A'),cur--; else ans.pb('B'); cnt--; while(cnt>0){ if(c){ if(a[cnt+1]>b[cnt]&&dp[cnt][cur][0]){ ans.pb('B'),c=0; cnt--; } else if(a[cnt+1]>a[cnt]&&cur>0&&dp[cnt][cur][1]){ ans.pb('A'),c=1; cnt--,cur--; } } else{ if(b[cnt+1]>b[cnt]&&dp[cnt][cur][0]){ ans.pb('B'),c=0; cnt--; } else if(b[cnt+1]>a[cnt]&&cur>0&&dp[cnt][cur][1]){ ans.pb('A'),c=1; cnt--,cur--; } } } if(cur) ans.pb('A'); else ans.pb('B'); reverse(all(ans)); cout<<ans; } return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...