This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifndef WAIMAI
#include "railroad.h"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const ll INF = 1e18;
const int SIZE = 16;
const int MAX = 1 << SIZE;
int n;
ll dp[MAX][SIZE];
ll plan_roller_coaster(vector<int> s, vector<int> t) {
n = s.size();
FOR (mask, 1, (1 << n) - 1) {
fill(dp[mask], dp[mask] + n, INF);
if (__builtin_popcount(mask) == 1) {
dp[mask][__lg(mask)] = 0;
continue;
}
FOR (i, 0, n - 1) if (mask >> i & 1) {
FOR (j, 0, n - 1) if (i != j && mask >> j & 1) {
dp[mask][i] = min(dp[mask][i], dp[mask ^ (1 << i)][j] + max(t[j] - s[i], 0));
}
}
}
return *min_element(dp[(1 << n) - 1], dp[(1 << n) - 1] + n);
}
/*
in1
4 1
1 7
4 3
5 8
6 6
out1
3
*/
#ifdef WAIMAI
int main() {
int n;
assert(1 == scanf("%d", &n));
vector<int> s(n), t(n);
for (int i = 0; i < n; ++i)
assert(2 == scanf("%d%d", &s[i], &t[i]));
long long ans = plan_roller_coaster(s, t);
printf("%lld\n", ans);
return 0;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |