Submission #1206337

#TimeUsernameProblemLanguageResultExecution timeMemory
1206337VMaksimoski008Building 4 (JOI20_building4)C++20
100 / 100
569 ms119828 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<array<int, 2> > a(2*n+1); for(int i=1; i<=2*n; i++) cin >> a[i][0]; for(int i=1; i<=2*n; i++) cin >> a[i][1]; vector<vector<int> > dpL(2*n+1, vector<int>(2, 1e9)); vector<vector<int> > dpR(2*n+1, vector<int>(2, -1e9)); dpL[1] = { 0, 1 }; dpR[1] = { 0, 1 }; for(int i=2; i<=2*n; i++) { for(int j=0; j<2; j++) { for(int k=0; k<2; k++) { if(a[i][j] >= a[i-1][k]) { dpL[i][j] = min(dpL[i][j], dpL[i-1][k] + j); dpR[i][j] = max(dpR[i][j], dpR[i-1][k] + j); } } } } string ans(2*n+1, 'A'); int l=n, pos=2*n, last = 2e9; for(; pos; pos--) { if(dpL[pos][0] <= l && l <= dpR[pos][0] && a[pos][0] <= last) { last = a[pos][0]; } else if(dpL[pos][1] <= l && l <= dpR[pos][1] && a[pos][1] <= last) { ans[pos]++; last = a[pos][1]; l--; } else { cout << -1; return 0; } } for(int i=1; i<=2*n; i++) cout << ans[i]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...