제출 #810181

#제출 시각아이디문제언어결과실행 시간메모리
810181vjudge1Building 4 (JOI20_building4)C++14
0 / 100
30 ms47956 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const int N = 5e5 ;
int n, a[2 * N + 1], b[2 * N + 1], dp[4 * N + 1] ;
vector<char> ans ;
bool us[4 * N + 1] ;
vector<int> v[4 * N + 1] ;
void dfs(int city)
{
    int mx = 0 ;
    us[city] = 1 ;
    if(city > n)dp[city]++ ;
    for(int i : v[city])
    {
        if(us[i])
        {
            mx = max(mx, dp[i]) ;
            continue ;
        }
        dfs(i) ;
        mx = max(mx, dp[i]) ;
    }
    dp[city] += mx ;
}
void get_ans(int city, int now)
{
    if(city <= n)
        ans.push_back('A') ;
    else
        ans.push_back('B') ;
    us[city] = 1 ;
    if(city % n == 0)
    {
        for(char i : ans)
            cout << i ;
        exit(0) ;
    }
    for(int i : v[city])
    {
        if(us[i] || now + dp[i] < n / 2)
            continue ;
        get_ans(i, now + (i > n)) ;
    }
    us[city] = 0 ;
    ans.pop_back() ;
}
void ultra_clear()
{
    for(int i = 1 ; i <= 2 * n ; i++)
        us[i] &= 0 ;
}
signed main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n ;
    n *= 2 ;
    for(int i = 1 ; i <= n ; i++)
        cin >> a[i] ;
    for(int i = 1 ; i <= n ; i++)
        cin >> b[i] ;
    for(int i = 1 ; i < n ; i++)
    {
        if(a[i] <= a[i + 1])
            v[i].push_back(i + 1) ;
        if(a[i] <= b[i + 1])
            v[i].push_back(n + i + 1) ;
        if(b[i] <= a[i + 1])
            v[n + i].push_back(i + 1) ;
        if(b[i] <= b[i + 1])
            v[n + i].push_back(n + i + 1) ;
    }
    dfs(1) ;
    dfs(n + 1) ;
    ultra_clear() ;
    get_ans(1, 0) ;
    ultra_clear() ;
    get_ans(n + 1, 1) ;
    cout << "-1\n" ;
    return 0 ;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...