제출 #682243

#제출 시각아이디문제언어결과실행 시간메모리
682243vjudge1건물 4 (JOI20_building4)C++17
11 / 100
424 ms208908 KiB
#include "bits/stdc++.h"
using namespace std;

// #define ORD_SET
// #define ROPE
#ifdef ORD_SET
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    template<typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#ifdef ROPE
    #include <ext/rope>
    using namespace __gnu_cxx;
#endif        

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// #define ll int
void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
void NotInteractive() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
void pre(ll a) { cout<<fixed<<setprecision(a); }
ll bit(ll x) { return __builtin_popcountll(x); }
ll binpow(ll x, ll y, ll z) { ll pow = 1; while(y) { if(y&1) pow *= x, pow %= z; x *= x, x %= z; y >>= 1; } return pow; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct sn { ll l, r, x; }; // a.swap(b)
ll B = 316;
const ll mod = (ll)1e9+7;
const ll inf = (ll)1e18+7;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const ld P = acos(-1.0);
const ll N = (ll)1e6+5;
ll a[N], b[N], dp[4005][2][2005];

void kigash() {
    ll n;
    cin>>n;
    for(ll i=1; i<=2*n; i++) cin>>a[i];
    for(ll i=1; i<=2*n; i++) cin>>b[i];
    dp[0][0][0] = dp[0][1][0] = 1;
    for(ll i=1; i<=2*n; i++) {
        for(ll j=1; j<=min(n, i); j++) {
            if(a[i-1]<=a[i]) dp[i][0][j] |= dp[i-1][0][j-1];
            if(b[i-1]<=a[i]) dp[i][0][j] |= dp[i-1][1][i-j];
            if(b[i-1]<=b[i]) dp[i][1][j] |= dp[i-1][1][j-1];
            if(a[i-1]<=b[i]) dp[i][1][j] |= dp[i-1][0][i-j];
        }
    }
    if(dp[2*n][0][n] || dp[2*n][1][n]) {
        string ans = (dp[2*n][0][n] ? "A" : "B");
        ll t = (ans=="A" ? 0 : 1), cur = n;
        for(ll i=2*n; i>1; i--) {
            if(!t) {
                if(a[i-1]<=a[i] && dp[i-1][0][cur-1]) ans += "A", cur--;
                else if(b[i-1]<=a[i] && dp[i-1][1][i-cur]) ans += "B", cur = i-cur, t = 1;
            }
            else {
                if(b[i-1]<=b[i] && dp[i-1][1][cur-1]) ans += "B", cur--;
                else if(a[i-1]<=b[i] && dp[i-1][0][i-cur]) ans += "A", cur = i-cur, t = 0;
            }
        }
        reverse(all(ans));
        cout<<ans<<"\n";
    }
    else cout<<"-1\n";
    return;
}

signed main(/**/) {
    // freopen("");
    NotInteractive();
    // precalc();
    
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) kigash();
    
    exit(0);
}

컴파일 시 표준 에러 (stderr) 메시지

building4.cpp: In function 'void freopen(std::string)':
building4.cpp:31:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
building4.cpp:31:75: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
      |                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...