Submission #600533

#TimeUsernameProblemLanguageResultExecution timeMemory
6005338e7Roller Coaster Railroad (IOI16_railroad)C++17
34 / 100
62 ms8508 KiB
#include "railroad.h"
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 16
#define pii pair<int, int>
#define ff first
#define ss second
const ll inf = 1LL<<60;
ll dp[1<<maxn][maxn];
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
    int n = (int) s.size();
	for (int i = 0;i < (1<<n);i++) {
		for (int j = 0;j < n;j++) dp[i][j] = inf;
	}
	for (int i = 0;i < n;i++) dp[1<<i][i] = 0;
	for (int i = 1;i < (1<<n);i++) {
		for (int j = 0;j < n;j++) {
			if ((i >> j) & 1) {
				for (int k = 0;k < n;k++) {
					if (!((i>>k)&1)) {
						dp[i + (1<<k)][k] = min(dp[i+(1<<k)][k], dp[i][j] + max(0, t[j] - s[k]));
					}
				}
			}
		}
	}
	ll ans = inf;
	for (int i = 0;i < n;i++) ans = min(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...