Submission #932602

#TimeUsernameProblemLanguageResultExecution timeMemory
932602AdamGSBuilding 4 (JOI20_building4)C++17
0 / 100
2 ms4700 KiB
#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const ll LIM=1e6+7; ll T[LIM][2], jaki[LIM], czy[LIM]; int co(int x) { if(jaki[x]) return -1; return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; n*=2; rep(i, n) { cin >> T[i][0]; T[i][0]*=2*n; T[i][0]+=(ll)(2*i); } rep(i, n) { cin >> T[i][1]; T[i][1]*=2*n; T[i][1]+=(ll)(2*i+1); } ll lst=0, sum=0; rep(i, n) { if(T[i][0]<T[i][1]) { if(lst<T[i][0]) { lst=T[i][0]; } else if(lst<T[i][1]) { lst=T[i][1]; jaki[i]=1; } else { cout << -1 << '\n'; return 0; } } else { if(lst<T[i][1]) { lst=T[i][1]; jaki[i]=1; } else if(lst<T[i][0]) { lst=T[i][0]; } else { cout << -1 << '\n'; return 0; } } sum+=co(i); } int p=n-1, bil=0; for(int i=n-1; i>=0; --i) { if(T[i][jaki[i]]>T[i][jaki[i]^1] || (i<n-1 && T[i][jaki[i]^1]>max(T[i+1][0], T[i+1][1]))) { p=i-1; bil=0; continue; } if(i==n-1 || T[i][jaki[i]^1]<T[i+1][jaki[i+1]]) { p=i; bil=0; } bil+=co(i); if(abs(sum-2*bil)<abs(sum)) { sum-=2*bil; for(int j=i; j<=p; ++j) jaki[j]^=1; p=i-1; bil=0; } } if(sum!=0) { cout << -1 << '\n'; return 0; } rep(i, n) cout << (jaki[i]?"B":"A"); cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...