Submission #595300

#TimeUsernameProblemLanguageResultExecution timeMemory
595300LastRoninRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
270 ms524288 KiB
#include "railroad.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pill pair<ll, ll>
#define mp make_pair
#define f first
#define s second
using namespace std;


ll plan_roller_coaster(vector<int> s, vector<int> t) {
	vector<pill> z;
    int n = (int) s.size();
    ll dp[1<<n][n];
    for(int i = 0; i < (1<<n); i++) {
     	for(int j = 0; j < n; j++)
     		dp[i][j] = 1e15;	
    }
	for(int i = 0; i < n; i++)
		dp[(1<<i)][i] = 0;
	ll ans = 1e15;
	for(int i = 1; i < (1<<n); i++) {
		for(int j = 0; j < n; j++) {
			if((1<<j)&i) {
				for(int k = 0; k < n; k++) {
					if((1<<k)&i)continue;
					dp[i^(1<<k)][k] = min(dp[i^(1<<k)][k], dp[i][j] + max(0, t[j] - s[k]));
				}
			}
			if(i == (1<<n) - 1) {
				ans = min(ans, dp[i][j]);
			}
		}
	}
    return ans;
}
/*
4
1 7
4 3
5 8
6 6
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...