제출 #611116

#제출 시각아이디문제언어결과실행 시간메모리
611116TemmieRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
637 ms28596 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); } struct MS { std::map <std::pair <int, int>, int> mp; size_t _size = 0; inline void insert(std::pair <int, int> p) { mp[p]++; _size++; } inline void erase(std::pair <int, int> p) { auto it = mp.find(p); if (!(--(it->second))) { mp.erase(it); } _size--; } inline std::pair <int, int> begin() { return mp.begin()->first; } inline size_t size() { return _size; } friend std::ostream& operator << (std::ostream& stream, const MS& ms) { stream << "{"; for (auto p : ms.mp) { assert(p.second); for (int i = 0; i < p.second; i++) { stream << " (" << p.first.first << ", " << p.first.second << ")"; } } stream << " }"; return stream; } }; 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); } MS st, ts; for (int i = 0; i < n; i++) { st.insert({ s[i], t[i] }); ts.insert({ t[i], s[i] }); } bool fl = false; for (int i = 0; i < n; i++) { auto p = st.begin(); st.erase(p); //std::cerr << st << std::endl; //std::cerr << i << ": " << p.first << ", " << p.second << std::endl; ts.erase({ p.second, p.first }); std::pair <int, int> pp; if ((pp = ts.begin()).first > p.first) { if (st.size() && st.begin().first >= p.second) { pp = st.begin(); st.erase(pp); ts.erase({ pp.second, pp.first }); p.second = pp.second; st.insert(p); ts.insert({ p.second, p.first }); continue; } if (fl) { return 1; } p.first = 1 << 30; st.erase({ pp.second, pp.first }); ts.erase(pp); st.insert(p); ts.insert({ p.second, p.first }); fl = true; continue; } p.first = pp.second; st.erase({ 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...