Submission #1134808

#TimeUsernameProblemLanguageResultExecution timeMemory
1134808domblyBuilding 4 (JOI20_building4)C++20
11 / 100
28 ms4164 KiB
#include <bits/stdc++.h> #define int long long #define F first #define S second #define pb push_back using namespace std; const int N = 5e5 + 10; const int inf = 1e15; const int mod = 1e9 + 7; int a[N],b[N],dp[N][2][2]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; n *= 2; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; vector<int> mna(n + 1, 1e9), mnb(n + 1, 1e9), mxa(n + 1, -1e9), mxb(n + 1, -1e9); mna[1] = mxa[1] = 1; mnb[1] = mxb[1] = -1; for(int i = 2; i <= n; i++) { if(a[i] >= a[i - 1]) { mxa[i] = max(mxa[i], mxa[i - 1]); mna[i] = min(mna[i], mna[i - 1]); } if(a[i] >= b[i - 1]) { mxa[i] = max(mxa[i], mxb[i - 1]); mna[i] = min(mna[i], mnb[i - 1]); } if(b[i] >= a[i - 1]) { mxb[i] = max(mxb[i], mxa[i - 1]); mnb[i] = min(mnb[i], mna[i - 1]); } if(b[i] >= b[i - 1]) { mxb[i] = max(mxb[i], mxb[i - 1]); mnb[i] = min(mnb[i], mnb[i - 1]); } mxa[i]++; mna[i]++; mxb[i]--; mnb[i]--; } if(min(mna[n], mnb[n]) > 0 || max(mxa[n], mxb[n]) < 0) { cout << -1; return 0; } int prv = inf,x = 0; string res; for(int i = n; i >= 1; i--) { if(a[i] > prv) { res += 'B'; prv = b[i]; x += 1; continue; } if(b[i] > prv) { res += 'A'; prv = a[i]; x -= 1; continue; } if(x >= mna[i] && x <= mxa[i]) { res += 'A'; prv = a[i]; x -= 1; }else { res += 'B'; prv = b[i]; x += 1; } } reverse(res.begin(),res.end()); cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...