Submission #1012767

#TimeUsernameProblemLanguageResultExecution timeMemory
1012767denislavBuilding 4 (JOI20_building4)C++17
0 / 100
30 ms21916 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) { if(k==0) ve.push_back('A'); else ve.push_back('B'); if(i==1) return ; if(v-1>=0 and dp[0][i-1][v-1]) rec(0,i-1,v-1); else rec(1,i-1,v+1); } 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<<k<<" "<<i<<" "<<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...