제출 #1029077

#제출 시각아이디문제언어결과실행 시간메모리
1029077c2zi6Roller Coaster Railroad (IOI16_railroad)C++14
0 / 100
211 ms31168 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "railroad.h"

namespace TEST2 {
    const int MAXN = 16;
    ll dp[1<<MAXN][MAXN];
    ll plan_roller_coaster(VI a, VI b) {
        int n = a.size();
        rep(s, 1<<n) rep(i, n) if (s & (1<<i)) {
            int st = (s^(1<<i));
            if (st == 0) {
                dp[s][i] = 0;
            } else {
                dp[s][i] = 1e18;
                rep(j, n) if (st & (1<<j)) {
                    setmin(dp[s][i], dp[st][j] + max(0, b[j]-a[i]));
                }
            }
        }
        ll ans = 1e18;
        rep(i, n) setmin(ans, dp[(1<<n)-1][i]);
        return ans;
    }
}

ll plan_roller_coaster(VI U, VI V) {
    /*if (U.size() <= 16) return TEST2::plan_roller_coaster(U, V);*/
    map<int, int> degree;
    rep(i, U.size()) {
        degree[U[i]]++;
        degree[V[i]]--;
    }
    VI a;
    for (auto p : degree) a.pb(p.ss);
    int n = a.size();
    if (n == 1) return 0;
    VI b(n);
    b[0] = +1;
    b[n-1] = -1;
    VI pref(n);
    rep(i, n) pref[i] = b[i] - a[i];
    replr(i, 1, n-1) pref[i] += pref[i-1];
    for (int x : pref) if (x < 0) return 1;
    return 0;
}




#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...