제출 #211815

#제출 시각아이디문제언어결과실행 시간메모리
211815mohamedsobhi777건물 4 (JOI20_building4)C++14
0 / 100
6 ms512 KiB
#include<bits/stdc++.h> using namespace std ; const int N = 5e5 + 7 ; int n ; int a[N] , b[N] ; int col[N] , v[N]; int A , B ; void print(){ for(int i = 0 ; i <n*2 ; i++){ cout<<char('A' + col[i] - 1) ; } } int main(){ ios_base::sync_with_stdio(0) ; cin.tie(0) ; // freopen("in.in" ,"r" , stdin) ; cin>>n ; for(int i =0 ; i < 2*n ; i++){ cin>>a[i] ; } for(int i = 0 ; i < 2*n ; i++){ cin>>b[i] ; } v[2*n] = 1e9+7; for(int i = n*2-1 ; i >=0 ; i--){ if(a[i] >= b[i]){ if(a[i] <= v[i+1]){ v[i] = a[i] ; col[i] = 1 ; A++; } else if(b[i] <= v[i+1]){ col[i] =2 ; v[i] = b[i] ; B++; } else return cout<<-1 , 0 ; } else { if(b[i] <=v[i+1]){ col[i] = 2; B++ ; v[i] = b[i] ; } else if(a[i] <=v[i+1] ){ col[i] = 1 ; A++ ; v[i] = a[i] ; } else return cout<<-1, 0 ; } } for(int i = 2*n -1 ; i>=0 ; i--){ if(A>B && col[i] == 1){ v[i] = b[i]; if( v[i] > v[i+1] || (i && v[i-1]>v[i]) ){ v[i] = a[i]; } else { A--; B++; col[i] = 2 ; } } if(B>A && col[i] ==2){ v[i] = a[i] ; if(v[i] > v[i+1] || (i && v[i-1] > v[i]) ){ v[i] = b[i] ; } else { B--; A++ ; col[i] = 1 ; } } } if(A!=B)return cout<<-1, 0 ; print() ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...