This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///
/// Oh? You're approaching me?
///
#include <bits/stdc++.h>
#define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x,l,r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define Kill(x) exit((cout << (x) << '\n', 0))
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
using namespace std;
const int N = 1'000'010;
int dpal[N], dpar[N];
int dpbl[N], dpbr[N];
int a[N], b[N];
int n;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n; n*=2;
Loop(i,0,n) cin >> a[i];
Loop(i,0,n) cin >> b[i];
dpal[0] = 1; dpar[0] = 2;
dpbl[0] = 0; dpbr[0] = 1;
Loop(i,1,n){
int l, r;
l = min(a[i-1]<=a[i]?dpal[i-1]:N-1, b[i-1]<=a[i]?dpbl[i-1]:N-1);
r = max(a[i-1]<=a[i]?dpar[i-1]:-1, b[i-1]<=a[i]?dpbr[i-1]:-1);
dpal[i] = l+1; dpar[i] = r+1;
l = min(a[i-1]<=b[i]?dpal[i-1]:N, b[i-1]<=b[i]?dpbl[i-1]:N);
r = max(a[i-1]<=b[i]?dpar[i-1]:0, b[i-1]<=b[i]?dpbr[i-1]:0);
dpbl[i] = l; dpbr[i] = r;
if(!(!dpar[i] || !dpbr[i] || max(dpal[i], dpbl[i]) <= min(dpar[i], dpbr[i]))){
cout <<"err\n";
}
}
if(!(dpal[n-1] <= n/2 && n/2 < dpar[n-1]) && !(dpbl[n-1] <= n/2 && n/2 < dpbr[n-1]))
Kill(-1);
int k=n/2, lst=1e9+10;
string ans;
LoopR(i,0,n){
if(dpal[i] <= k && k < dpar[i] && a[i]<=lst){
ans.push_back('A');
lst=a[i];
--k;
} else {
ans.push_back('B');
lst=b[i];
}
}
reverse(ans.begin(), ans.end());
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |