Submission #153224

#TimeUsernameProblemLanguageResultExecution timeMemory
153224qkxwsmRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
89 ms17124 KiB
#include "railroad.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 200013
#define INF 1000000007
#define LLINF 2696969696969696969

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
pll arr[MAXN];
ll dp[(1 << 17)][17];
ll ans = LLINF;

ll plan_roller_coaster(vector<int> s, vector<int> t)
{
	N = SZ(s);
	FOR(i, 0, N)
	{
		arr[i] = {s[i], t[i]};
	}
	// arr[N] = {INF, 0};
	// N++;
	for (int i = 0; i < (1 << N); i++)
	{
		for (int j = 0; j < N; j++)
		{
			dp[i][j] = LLINF;
		}
	}
	for (int i = 0; i < N; i++)
	{
		dp[(1 << i)][i] = 0;
	}
	for (int i = 0; i < (1 << N); i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (!(i & (1 << j)))
			{
				continue;
			}
			for (int k = 0; k < N; k++)
			{
				if (i & (1 << k))
				{
					continue;
				}
				dp[i + (1 << k)][k] = min(dp[i + (1 << k)][k], dp[i][j] + max(0ll, arr[j].se - arr[k].fi));
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		ckmin(ans, dp[(1 << N) - 1][i]);
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...