Submission #556288

#TimeUsernameProblemLanguageResultExecution timeMemory
556288Talha_TakiRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
274 ms524288 KiB
#include <bits/stdc++.h> #include "railroad.h" using namespace std; typedef long long ll; typedef pair <int, int> pii; ll plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = s.size(); vector <vector <ll>> w(n, vector <ll> (n)); for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if (i == j) w[i][i] = 0; else w[i][j] = max(0LL, (ll)t[i] - s[j]); } } const ll INF = 1e18; vector <vector <ll>> dp(n, vector <ll> (1<<n, INF)); for(int i = 0; i < n; ++i) { dp[i][i] = 0; dp[i][1<<i] = 0; } for(int mask = 1; mask < 1<<n; ++mask) { for(int j = 0; j < n; ++j) { if (!(mask & (1<<j))) continue; for(int k = 0; k < n; ++k) { if (j == k) continue; if (!(mask & (1<<k))) continue; dp[j][mask] = min(dp[j][mask], dp[k][mask ^ (1<<j)] + w[k][j]); } } } ll ans = INF; for(int i = 0; i < n; ++i) { ans = min(ans, dp[i][(1<<n)-1]); } 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...