Submission #1123817

#TimeUsernameProblemLanguageResultExecution timeMemory
1123817IcelastBuilding 4 (JOI20_building4)C++20
100 / 100
355 ms69088 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; struct segment{ int l, r; }; void solve(){ int n; cin >> n; vector<int> a(n*2+1), b(n*2+1); for(int i = 1; i <= 2*n; i++){ cin >> a[i]; } for(int i = 1; i <= 2*n; i++){ cin >> b[i]; } a[0] = 0; vector<vector<segment>> f(n*2+1, vector<segment>(2, {-1, -1})); auto merge = [&](segment &a, segment b) -> void{ if(b.l == -1) return; if(a.l == -1){ a = b; return; } a.l = min(a.l, b.l); a.r = max(a.r, b.r); }; f[0][0] = {0, 0}; for(int i = 1; i <= n*2; i++){ //AA if(a[i] >= a[i-1]){ if(f[i-1][0].l != -1){ merge(f[i][0], {f[i-1][0].l+1, f[i-1][0].r+1}); } } //BA if(a[i] >= b[i-1]){ if(f[i-1][1].l != -1){ merge(f[i][0], {f[i-1][1].l+1, f[i-1][1].r+1}); } } //AB if(b[i] >= a[i-1]){ if(f[i-1][0].l != -1){ merge(f[i][1], f[i-1][0]); } } //BB if(b[i] >= b[i-1]){ if(f[i-1][1].l != -1){ merge(f[i][1], f[i-1][1]); } } } if((f[n*2][0].l > n || f[n*2][0].r < n) && (f[n*2][1].l > n || f[n*2][1].r < n)){ cout << -1; return; } vector<char> ans; int p = n*2, cur = n; int pre = 1e9; while(p > 0){ if(f[p][0].l <= cur && cur <= f[p][0].r && a[p] <= pre){ ans.push_back('A'); cur--; pre = a[p]; }else{ ans.push_back('B'); pre = b[p]; } p--; } reverse(ans.begin(), ans.end()); vector<int> c(n*2+1, 0); for(int i = 1; i <= 2*n; i++){ if(ans[i-1] == 'A'){ c[i] = a[i]; }else{ c[i] = b[i]; } if(c[i] < c[i-1]){ } } for(auto it : ans) cout << it; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("main.inp", "r", stdin); //freopen("main.out", "w", stdout); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...