Submission #611096

#TimeUsernameProblemLanguageResultExecution timeMemory
611096TemmieRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
2078 ms22152 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, ts; for (int i = 0; i < n; i++) { st.insert({ s[i], t[i] }); st.insert({ t[i], s[i] }); } for (int i = 0; i < n - 1; i++) { auto p = *st.begin(); st.erase(st.begin()); ts.erase(ts.find({ p.second, p.first })); std::pair <int, int> pp; if ((pp = *ts.begin()).first > p.first) { return 1; } p.first = p.second; st.erase(st.find({ pp.second, pp.first })); ts.erase(pp); st.insert(p); ts.insert({ p.second, p.first }); } 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...