Submission #1022085

#TimeUsernameProblemLanguageResultExecution timeMemory
1022085AmirAli_H1Roller Coaster Railroad (IOI16_railroad)C++17
34 / 100
35 ms10580 KiB
// In the name of Allah

#include <bits/stdc++.h>
#include "railroad.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 18;
const ll oo = 1e18 + 4;

int n; pll A[maxn];
ll dp[1 << maxn][maxn];

ll plan_roller_coaster(vector<int> s, vector<int> t) {
    n = len(s);
    for (int i = 0; i < n; i++) A[i] = Mp(s[i], t[i]);
    
    for (int mask = 1; mask < (1 << n); mask++) {
    	int x = mask;
    	while (x > 0) {
    		int j = __builtin_ctz(x);
			x ^= (1 << j);
			
			dp[mask][j] = oo;
    		int y = mask ^ (1 << j);
    		if (y == 0) dp[mask][j] = 0;
    		while (y > 0) {
    			int k = __builtin_ctz(y);
				y ^= (1 << k);
				dp[mask][j] = min(dp[mask][j], dp[mask ^ (1 << j)][k] + max(0ll, A[k].S - A[j].F));
			}
		}
	}
    
    ll ans = oo;
    for (int j = 0; j < n; j++) ans = min(ans, dp[(1 << n) - 1][j]);
    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...