Submission #1099579

#TimeUsernameProblemLanguageResultExecution timeMemory
1099579vladiliusBuilding 4 (JOI20_building4)C++17
11 / 100
556 ms524288 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; int m = 2 * n; vector<int> a(m + 1), b(m + 1); for (int i = 1; i <= m; i++) cin>>a[i]; for (int i = 1; i <= m; i++) cin>>b[i]; const int N = 2e3 + 1; bitset<N> bt[m + 1][2]; bt[1][0].set(1, 1); bt[1][1].set(0, 1); for (int i = 2; i <= m; i++){ if (a[i - 1] <= a[i]) bt[i][0] |= (bt[i - 1][0] << 1); if (b[i - 1] <= a[i]) bt[i][0] |= (bt[i - 1][1] << 1); if (a[i - 1] <= b[i]) bt[i][1] |= bt[i - 1][0]; if (b[i - 1] <= b[i]) bt[i][1] |= bt[i - 1][1]; } auto get = [&](int x, int y, int b){ return bt[x][b][y]; }; if (get(m, n, 0) || get(m, n, 1)){ vector<bool> all; int i = m, j = n, c = get(m, n, 0) ? 0 : 1; while (true){ all.pb(c); if (i == 1) break; if (c){ if (a[i - 1] <= b[i] && get(i - 1, j, 0)){ c = 0; } } else { if (b[i - 1] <= a[i] && get(i - 1, j - 1, 1)){ c = 1; } j--; } i--; } reverse(all.begin(), all.end()); for (bool i: all) cout<<((i) ? "B" : "A"); cout<<"\n"; } else { cout<<-1<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...