Submission #611095

#TimeUsernameProblemLanguageResultExecution timeMemory
611095TemmieRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
127 ms12736 KiB
#include <bits/stdc++.h> long long sub12(int n, std::vector <int> s, std::vector <int> t) { t.push_back(1); long long dp[1 << 16][17]; for (int mask = 0; mask < (1 << 16); mask++) { for (int i = 0; i < 17; i++) { dp[mask][i] = 1LL << 60; } } for (int i = 0; i < 17; i++) { dp[(1 << n) - 1][i] = 0; } auto f = [&] (auto&& self, int mask, int last) -> long long { if (dp[mask][last] < (1LL << 60)) { return dp[mask][last]; } for (int i = 0; i < n; i++) { if (mask & (1 << i)) { continue; } dp[mask][last] = std::min(dp[mask][last], self(self, mask | (1 << i), i) + std::max(0, t[last] - s[i])); } return dp[mask][last]; }; return f(f, 0, n); } long long plan_roller_coaster(std::vector <int> s, std::vector <int> t) { int n = s.size(); if (n <= 16) { return sub12(n, s, t); } std::multiset <std::pair <int, int>> st; for (int i = 0; i < n; i++) { st.insert({ s[i], t[i] }); } for (int i = 0; i < n - 1; i++) { auto p = *st.begin(); st.erase(st.begin()); if (st.begin()->second > p.first) { return 1; } p.first = st.begin()->first; st.erase(st.begin()); st.insert(p); } 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...