제출 #248523

#제출 시각아이디문제언어결과실행 시간메모리
248523MladenP건물 4 (JOI20_building4)C++17
11 / 100
301 ms40568 KiB
#include<bits/stdc++.h> #define PRINT(x) cerr<<#x<<'='<<x<<endl; #define NL(x) " \n"[(x)] #define lld long long #define pil pair<int,lld> #define pli pair<lld,int> #define pll pair<lld,lld> #define pii pair<int,int> #define pb push_back #define fi first #define se second #define mid (l+r)/2 #define endl '\n' #define all(a) begin(a),end(a) #define sz(a) int((a).size()) #define LINF 1000000000000000LL #define INF 1000000000 #define EPS 1e-9 using namespace std; #define MAXN 500010 int A[2*MAXN], B[MAXN]; pii Ai[2*MAXN], Bi[2*MAXN]; pii unija(pii A, pii B) { return {min(A.fi, B.fi), max(A.se, B.se)}; } bool in(int x, pii A) { return (A.fi <= x && x <= A.se); } int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0); 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++) Ai[i] = Bi[i] = {INF, -INF}; Ai[2*N] = {1, 1}; Bi[2*N] = {0, 0}; for(int i = 2*N-1; i >= 1; i--) { if(A[i] <= A[i+1]) Ai[i] = unija(Ai[i], Ai[i+1]); if(A[i] <= B[i+1]) Ai[i] = unija(Ai[i], Bi[i+1]); Ai[i] = {Ai[i].fi+1, Ai[i].se+1}; if(B[i] <= A[i+1]) Bi[i] = unija(Bi[i], Ai[i+1]); if(B[i] <= B[i+1]) Bi[i] = unija(Bi[i], Bi[i+1]); } if(!in(N, Ai[1]) && !in(N, Bi[1])) cout << -1; else { int cnt = N, prev = 0; for(int i = 1; i <= 2*N; i++) { if(prev <= A[i] && in(cnt, Ai[i])) { cout << 'A'; prev = A[i]; cnt--; } else if(prev <= B[i] && in(cnt, Bi[i])) { prev = B[i]; cout << 'B'; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...