제출 #558741

#제출 시각아이디문제언어결과실행 시간메모리
558741elazarkorenRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
47 ms8608 KiB
#include "railroad.h" #include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vii; const ll infinity = 1e18; const int MAX_N = 16; ll dp[1 << MAX_N][MAX_N]; ll plan_roller_coaster(vi s, vi t) { int n = s.size(); for (int i = 1; i < (1 << n); i++) { for (int j = 0; j < n; j++) dp[i][j] = infinity; if (__builtin_popcount(i) == 1) { dp[i][__builtin_ctz(i)] = 0; continue; } for (int j = 0; j < n; j++) { if (!((i >> j) & 1)) continue; int mask = i ^ (1 << j); for (int k = 0; k < n; k++) { chkmin(dp[i][j], dp[mask][k] + max(0, t[k] - s[j])); } } } ll ans = infinity; for (int i = 0; i < n; i++) chkmin(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...