제출 #637642

#제출 시각아이디문제언어결과실행 시간메모리
637642dxz05건물 4 (JOI20_building4)C++14
0 / 100
0 ms340 KiB
//#pragma GCC optimize("Ofast,O2,O3,unroll-loops") //#pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << "[" << H << "]"; debug_out(T...); } #ifdef dddxxz #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SZ(s) ((int)s.size()) #define all(x) (x).begin(), (x).end() #define lla(x) (x).rbegin(), (x).rend() #define bpc(x) __builtin_popcount(x) #define bpcll(x) __builtin_popcountll(x) #define MP make_pair clock_t startTime; int getCurrentTime() { return int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef long long ll; const int MOD = 998244353; const int INF = 1000000101; const long long LLINF = 1223372000000000555; const int N = 1e6 + 3e2; int a[N], b[N]; int dpl[N][2], pl[N][2]; int dpr[N][2], pr[N][2]; bool chmin(int &x, int y){ if (x <= y) return false; x = y; return true; } bool chmax(int &x, int y){ if (x >= y) return false; x = y; return true; } void solve(int TC) { int n; 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++){ dpl[i][0] = dpl[i][1] = INF; dpr[i][0] = dpr[i][1] = -INF; pl[i][0] = pl[i][1] = -1; pr[i][0] = pr[i][1] = -1; } dpl[1][0] = 1; dpl[1][1] = 0; dpr[1][0] = 1; dpr[1][1] = 0; for (int i = 2; i <= 2 * n; i++){ if (a[i] >= a[i - 1]){ if (chmin(dpl[i][0], dpl[i - 1][0] + 1)) pl[i][0] = 0; if (chmax(dpr[i][0], dpr[i - 1][0] + 1)) pr[i][0] = 0; } if (a[i] >= b[i - 1]){ if (chmin(dpl[i][0], dpl[i - 1][1] + 1)) pl[i][0] = 1; if (chmax(dpr[i][0], dpr[i - 1][1] + 1)) pr[i][0] = 1; } if (b[i] >= a[i - 1]){ if (chmin(dpl[i][1], dpl[i - 1][0])) pl[i][1] = 0; if (chmax(dpr[i][1], dpr[i - 1][0])) pr[i][1] = 0; } if (b[i] >= b[i - 1]){ if (chmin(dpl[i][1], dpl[i - 1][1])) pl[i][1] = 1; if (chmax(dpr[i][1], dpr[i - 1][1])) pr[i][1] = 1; } } int i = 2 * n; int x = -1; if (dpl[2 * n][0] <= n && n <= dpr[2 * n][0]) x = 0; if (dpl[2 * n][1] <= n && n <= dpr[2 * n][1]) x = 1; if (x == -1){ cout << -1; return; } string s; if (x == 0){ s += 'A'; n--; } else { s += 'B'; } while (i > 1){ int y = pl[i][x]; if (y == 0){ s += 'A'; n--; } else { s += 'B'; } x = y; i--; } reverse(all(s)); cout << s << endl; } int main() { startTime = clock(); ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef dddxxz freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int TC = 1; //cin >> TC; for (int test = 1; test <= TC; test++) { //debug(test); //cout << "Case #" << test << ": "; solve(test); } #ifdef dddxxz cerr << endl << "Time: " << getCurrentTime() << " ms" << endl; #endif return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...