제출 #381397

#제출 시각아이디문제언어결과실행 시간메모리
381397KULIKOLD건물 4 (JOI20_building4)C++17
0 / 100
2 ms492 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define x1 fdgfdgf #define y1 fdhfdgfdg #define endl '\n' const ll DIM = 1E6+7; const ll INF = 1E18; ll A[2][DIM],ans[DIM]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin>>n; n*=2; ll last = 0; for(ll i = 1;i<=n;++i) { cin>>A[0][i]; } for(ll i = 1;i<=n;++i){ cin>>A[1][i]; } ll cnt[] = {0,0}; for(ll i = 1;i<=n;++i){ if (min(A[0][i],A[1][i])>=last){ if (A[0][i]<A[1][i])ans[i] = 0,++cnt[0]; else ans[i] = 1,++cnt[1]; last = min(A[0][i],A[1][i]); } else if (max(A[0][i],A[1][i])>=last){ if (A[0][i]>A[1][i])ans[i] = 0,++cnt[0]; else ans[i] = 1,++cnt[1]; last = max(A[0][i],A[1][i]); } else{ cout<<"-1\n"; return 0; } } A[0][n+1] = A[1][n+1] = INF; for(ll i = n;i>=1;--i){ if (cnt[0]<cnt[1] && ans[i]==1 && A[0][i]<=A[ans[i+1]][i+1] && A[0][i]>=A[ans[i-1]][i-1]){ ++cnt[0]; --cnt[1]; ans[i] = 0; } if (cnt[1]<cnt[0] && ans[i]==0 && A[1][i]<=A[ans[i+1]][i+1] && A[1][i]>=A[ans[i-1]][i-1]){ ++cnt[1]; --cnt[0]; ans[i] = 1; } } if (cnt[1]!=cnt[0]){ cout<<"-1\n"; } for(ll i = 1;i<=n;++i){ if (ans[i])cout<<'B'; else cout<<'A'; } cout<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...