Submission #530579

#TimeUsernameProblemLanguageResultExecution timeMemory
530579cheissmartBuilding 4 (JOI20_building4)C++14
100 / 100
266 ms44072 KiB
#include <bits/stdc++.h> #define IO_OP ios::sync_with_stdio(0), cin.tie(0) #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(v) int((v).size()) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7; signed main() { IO_OP; int n; cin >> n; n *= 2; V<array<int, 2>> a(n); for(int i = 0; i < n; i++) cin >> a[i][0]; for(int i = 0; i < n; i++) cin >> a[i][1]; V<array<int, 2>> l(n, {INF, INF}), r(n, {-INF, -INF}); auto upd = [&] (int i, int j, int L, int R) { l[i][j] = min(l[i][j], L); r[i][j] = max(r[i][j], R); }; upd(0, 0, 0, 0); upd(0, 1, 1, 1); for(int i = 1; i < n; i++) { for(int j = 0; j < 2; j++) if(l[i - 1][j] <= r[i - 1][j]) { for(int k = 0; k < 2; k++) { if(a[i - 1][j] <= a[i][k]) { int L = l[i - 1][j] + k, R = r[i - 1][j] + k; upd(i, k, L, R); } } } } int j = -1; for(int i = 0; i < 2; i++) { if(l[n - 1][i] <= n / 2 && n / 2 <= r[n - 1][i]) j = i; } if(j == -1) { cout << -1 << '\n'; return 0; } int i = n - 1, need = n / 2; string s; while(i >= 0) { assert(l[i][j] <= need && need <= r[i][j]); s += 'A' + j; need -= j; if(i == 0) break; for(int k = 0; k < 2; k++) { if(a[i][j] >= a[i - 1][k] && l[i - 1][k] <= need && need <= r[i - 1][k]) { j = k; break; } } i--; } reverse(ALL(s)); cout << s << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...