제출 #568492

#제출 시각아이디문제언어결과실행 시간메모리
568492losmi247건물 4 (JOI20_building4)C++14
0 / 100
3 ms412 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6+56; int n,a[N],b[N],c[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= 2*n; i++){ cin >> a[i]; } for(int i = 1; i <= 2*n; i++){ cin >> b[i]; } string s = ""; int cnta = 0; for(int i = 1; i <= 2*n; i++){ if(a[i] < b[i]){ if(a[i] >= c[i-1]){ s += "A"; cnta++; c[i] = a[i]; } else{ if(b[i] < c[i-1]){ cout << -1 << endl; return 0; } s += "B"; c[i] = b[i]; } } else{ if(b[i] >= c[i-1]){ s += "B"; c[i] = b[i]; } else{ if(a[i] < c[i-1]){ cout << -1 << endl; return 0; } s += "A"; cnta++; c[i] = a[i]; } } } //cout << "pre " << s << " " << cnta << endl; if(cnta > n){ for(int i = 2*n; i >= 1; i--){ if(cnta == n) break; if(s[i-1] == 'B') continue; if((i == 1 || b[i] >= c[i-1]) && (i == 2*n || b[i] <= c[i+1])){ cnta--; c[i] = b[i]; s[i-1] = 'B'; } } if(cnta != n){ cout << -1 << endl; return 0; } } else if(cnta < n){ for(int i = 2*n; i >= 1; i--){ if(cnta == n) break; if(s[i-1] == 'A') continue; if((i == 1 || a[i] >= c[i-1]) && (i == 2*n || a[i] <= c[i+1])){ cnta++; c[i] = a[i]; s[i-1] = 'A'; } } if(cnta != n){ cout << -1 << endl; return 0; } } cout << s << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...