Submission #1039801

#TimeUsernameProblemLanguageResultExecution timeMemory
1039801peraBuilding 4 (JOI20_building4)C++17
100 / 100
174 ms28888 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 1 , oo = 1e9; int n; int A[N][2] , mn[N][2] , mx[N][2]; char t[2] = {'A' , 'B'}; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; n *= 2; for(int x = 0;x < 2;x ++){ for(int i = 1;i <= n;i ++){ cin >> A[i][x]; } } for(int i = 1;i <= n;i ++){ for(int x = 0;x < 2;x ++){ mn[i][x] = oo; mx[i][x] = 0; for(int y = 0;y < 2;y ++){ if(A[i][x] >= A[i - 1][y]){ mn[i][x] = min(mn[i][x] , mn[i - 1][y] + !x); mx[i][x] = max(mx[i][x] , mx[i - 1][y] + !x); } } } } for(int x = 0;x < 2;x ++){ if(mn[n][x] <= n / 2 && n / 2 <= mx[n][x]){ int ans[n + 1]; int v = n , e = x , cnt = 0; while(v >= 1){ ans[v] = e; cnt += !e; --v; if(A[v + 1][e] >= A[v][0] && mn[v][0] + cnt <= n / 2 && n / 2 <= mx[v][0] + cnt){ e = 0; }else{ e = 1; } } for(int i = 1;i <= n;i ++){ cout << t[ans[i]]; } cout << endl; return 0; } } cout << -1 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...