Submission #1012783

#TimeUsernameProblemLanguageResultExecution timeMemory
1012783denislavBuilding 4 (JOI20_building4)C++14
11 / 100
44 ms32084 KiB
# include <iostream> # include <vector> # include <algorithm> using namespace std; const int MAX=4e3+11; int a[2][MAX]; bool dp[2][MAX][MAX]; int n; vector<char> ve; void rec(int k, int i, int v) { //cout<<"->"<<k<<" "<<i<<" "<<v-n<<"\n"; if(k==0) ve.push_back('A'); else ve.push_back('B'); if(i==1) return ; int d=1; if(k==1) d=-1; if(v-d>=0 and v-d<=n*2 and dp[0][i-1][v-d]==1 and a[0][i-1]<=a[k][i]) rec(0,i-1,v-d); else rec(1,i-1,v-d); } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n; for(int k=0;k<=1;k++) { for(int i=1;i<=n*2;i++) cin>>a[k][i]; } dp[0][1][n+1]=1; dp[1][1][n-1]=1; for(int i=1;i<n*2;i++) { for(int k=0;k<=1;k++) { for(int v=0;v<=n*2;v++) { if(dp[k][i][v]==0) continue; //cout<<i<<" "<<k<<" "<<v-n<<"\n"; if(a[k][i]<=a[0][i+1] and v+1<=n*2) dp[0][i+1][v+1]=1; if(a[k][i]<=a[1][i+1] and v-1>=0) dp[1][i+1][v-1]=1; } } } if(!(dp[0][n*2][n]==1 or dp[1][n*2][n]==1)) {cout<<-1<<"\n";return 0;} if(dp[0][n*2][n]==1) rec(0,n*2,n); else rec(1,n*2,n); reverse(ve.begin(),ve.end()); for(char x: ve) cout<<x; cout<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...