Submission #998784

#TimeUsernameProblemLanguageResultExecution timeMemory
998784snpmrnhlolBuilding 4 (JOI20_building4)C++17
0 / 100
3 ms2504 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5e5; const int inf = 2e9; struct xy{ int x,y; }v[N]; bool ans[N]; int main(){ bool ok = 1; int prv = -1; int cnt = 0; int n; cin>>n; for(int i = 0;i < 2*n;i++){ cin>>v[i].x; } for(int i = 0;i < 2*n;i++){ cin>>v[i].y; } for(int i = 0;i < 2*n;i++){ if(v[i].x <= v[i].y){ ///v[i].x if(prv <= v[i].x){ ans[i] = 0; prv = v[i].x; }else if(prv <= v[i].y){ ans[i] = 1; prv = v[i].y; cnt++; }else ok = 0; }else{ if(prv <= v[i].y){ ans[i] = 1; prv = v[i].y; cnt++; }else if(prv <= v[i].x){ ans[i] = 0; prv = v[i].x; }else ok = 0; } prv = (ans[i] == 0?v[i].x:v[i].y); } if(cnt == n && ok){ for(int i = 0;i < 2*n;i++){ cout<<(ans[i] == 0?"A":"B"); } return 0; } prv = inf; for(int i = 2*n - 1;i >= 0;i--){ cnt-=ans[i]; if(v[i].x <= v[i].y){ if(prv >= v[i].y){ ans[i] = 1; prv = v[i].y; }else if(prv >= v[i].x){ ans[i] = 0; prv = v[i].x; }else ok = 0; }else{ if(prv >= v[i].x){ ans[i] = 0; prv = v[i].x; }else if(prv >= v[i].y){ ans[i] = 1; prv = v[i].y; }else ok = 0; } cnt+=ans[i]; prv = (ans[i] == 0?v[i].x:v[i].y); if(cnt == n && ok){ for(int i = 0;i < 2*n;i++){ cout<<(ans[i] == 0?"A":"B"); } return 0; } } cout<<-1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...