Submission #962632

#TimeUsernameProblemLanguageResultExecution timeMemory
962632CookieBuilding 4 (JOI20_building4)C++14
100 / 100
209 ms45504 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; #define sz(a) (int)a.size() #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> #define mpp make_pair const ld PI = 3.14159265359, prec = 1e-9;; //using u128 = __uint128_t; //const int x[4] = {1, 0, -1, 0}; //const int y[4] = {0, -1, 0, 1}; const ll mod = 1e9 + 7, pr = 31; const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1; //const int base = (1 <<18); const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // have fun! int n; int mx[mxn + 1][2], mn[mxn + 1][2], a[mxn + 1], b[mxn + 1]; void ckmin(int &a, int b){ if(a > b)a = b; } void ckmax(int &a, int b){ if(a < b)a = b; } void solve(){ cin >> n; for(int i = 1; i <= 2 * n; i++)cin >> a[i]; for(int i = 1; i <= 2 * n; i++)cin >> b[i]; for(int i = 1; i <= 2 * n; i++){ mn[i][0] = mn[i][1] = inf; mx[i][0] = mx[i][1] = 0; } //minimum and maximum Bs mn[1][0] = mx[1][0] = 0; mn[1][1] = mx[1][1] = 1; for(int i = 1; i < 2 * n; i++){ if(a[i] <= a[i + 1]){ ckmin(mn[i + 1][0], mn[i][0]); ckmax(mx[i + 1][0], mx[i][0]); }if(a[i] <= b[i + 1]){ ckmin(mn[i + 1][1], mn[i][0] + 1); ckmax(mx[i + 1][1], mx[i][0] + 1); }if(b[i] <= a[i + 1]){ ckmin(mn[i + 1][0], mn[i][1]); ckmax(mx[i + 1][0], mx[i][1]); }if(b[i] <= b[i + 1]){ ckmin(mn[i + 1][1], mn[i][1] + 1); ckmax(mx[i + 1][1], mx[i][1] + 1); } } int id = 2 * n, type; if(mx[2 * n][0] >= n && mn[2 * n][0] <= n)type = 0; else if(mx[2 * n][1] >= n && mn[2 * n][1] <= n)type = 1; else{ cout << -1; return; } int taken = 0; string ans = ""; while(1){ ans += ((type == 0) ? 'A' : 'B'); if(id == 1)break; taken += type; int v = ((type == 0) ? a[id] : b[id]); if(a[id - 1] <= v && mx[id - 1][0] + taken >= n && mn[id - 1][0] + taken <= n)type = 0; else if(b[id - 1] <= v && mx[id - 1][1] + taken >= n && mn[id - 1][1] + taken <= n)type = 1; id--; } reverse(ALL(ans)); cout << ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("DATA.inp", "r", stdin); //freopen("DATA.out", "w", stdout); int tt; tt = 1; while(tt--){ solve(); } return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...