Submission #752092

#TimeUsernameProblemLanguageResultExecution timeMemory
752092sofija6건물 4 (JOI20_building4)C++14
0 / 100
2 ms468 KiB
#include <bits/stdc++.h>
#define ll long long
#define MAXN 1000010
using namespace std;
ll a[2][MAXN];
pair<ll,ll> dp[2][MAXN];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    for (ll i=0;i<2;i++)
    {
        for (ll j=1;j<=2*n;j++)
        {
            cin >> a[i][j];
            dp[i][j]={LLONG_MAX,LLONG_MIN};
        }
    }
    for (ll i=1;i<=2*n;i++)
    {
        for (ll j=0;j<2;j++)
        {
            if (a[0][i]>=a[j][i-1])
            {
                dp[0][i].first=min(dp[0][i].first,dp[j][i-1].first+1);
                dp[0][i].second=max(dp[0][i].second,dp[j][i-1].second+1);
            }
            if (a[1][i]>=a[j][i-1])
            {
                dp[1][i].first=min(dp[1][i].first,dp[j][i-1].first);
                dp[1][i].second=max(dp[1][i].second,dp[j][i-1].second);
            }
        }
    }
    if ((dp[0][2*n].second<n || dp[0][2*n].first>n) && (dp[1][2*n].second<n || dp[1][2*n].first>n))
    {
        cout << -1 << "\n";
        return 0;
    }
    ll curi,curj=2*n,val=n;
    string ans;
    curi=dp[0][2*n].first<=n && dp[0][2*n].second>=n?0 : 1;
    ans=curi?"B" : "A";
    while (curj>1)
    {
        val-=1-curi;
        curi=dp[0][curj-1].first<=val && dp[0][curj-1].second>=val && a[0][curj-1]<=a[curi][curj]?0 : 1;
        ans=(curi?'B' : 'A')+ans;
        curj--;
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...