Submission #23735

#TimeUsernameProblemLanguageResultExecution timeMemory
23735NirjhorRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
123 ms15944 KiB
#include <bits/stdc++.h> #include "railroad.h" using namespace std; typedef long long ll; const int N = 18; const ll INF = 1e17 + 10; const int MASK = (1 << 16) + 10; int n, done; vector <int> s, t; ll dp[N][MASK]; ll call (int last, int mask) { if (mask == done) return 0; ll &ret = dp[last][mask]; if (ret != -1) return ret; ret = INF; for (int i = 0; i < n; ++i) { if (mask & 1 << i) continue; ret = min(ret, (ll) max(0, t[last] - s[i]) + call(i, mask | 1 << i)); } return ret; } ll plan_roller_coaster (vector <int> s_in, vector <int> t_in) { s = s_in, t = t_in; n = s.size(); done = (1 << n) - 1; memset(dp, -1, sizeof dp); ll ans = INF; for (int i = 0; i < n; ++i) { ans = min(ans, call(i, 1 << i)); } return ans; } // int main (int argc, char const *argv[]) { // int nn; cin >> nn; // vector <int> ss(nn), tt(nn); // for (int i = 0; i < nn; ++i) { // cin >> ss[i]; // } // for (int i = 0; i < nn; ++i) { // cin >> tt[i]; // } // cout << plan_roller_coaster(ss, tt) << endl; // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...