Submission #807490

#TimeUsernameProblemLanguageResultExecution timeMemory
807490happypotatoRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
172 ms19096 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define ff first #define ss second vector<int> s, t; int n; int BruteDP() { int dp[(1 << n)][n]; for (int conf = 0; conf < (1 << n); conf++) { for (int i = 0; i < n; i++) { dp[conf][i] = (conf == (1 << i) ? 0 : 1e18); } } for (int bit = 2; bit <= n; bit++) { for (int conf = 0; conf < (1 << n); conf++) { if (__builtin_popcountll(conf) != bit) continue; for (int i = 0; i < n; i++) { if (conf & (1 << i)) { for (int j = 0; j < n; j++) { if (!bool(conf & (1 << j)) || i == j) continue; dp[conf][i] = min(dp[conf][i], dp[conf ^ (1 << i)][j] + max(0LL, t[j] - s[i])); } } } } } int ans = 1e18; for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]); return ans; } long long plan_roller_coaster(vector<int32_t> S, vector<int32_t> T) { n = S.size(); s.resize(n); t.resize(n); for (int i = 0; i < n; i++) { s[i] = S[i]; t[i] = T[i]; } // for (int i = 0; i < n; i++) cerr << s[i] << ' '; cerr << endl; // for (int i = 0; i < n; i++) cerr << t[i] << ' '; cerr << endl; // if (n <= 16) return BruteDP(); vector<pii> v(n); for (int i = 0; i < n; i++) { v[i] = {s[i], t[i]}; } sort(v.begin(), v.end(), greater<pii>()); set<int> s; bool ans = 1; for (int st = n - 1; st >= max(1LL, n - 2); st--) { s.clear(); for (int i = 0; i < n; i++) s.insert(i); ans = 0; int cur = st; for (int turns = 0; turns < n; turns++) { s.erase(s.find(cur)); if (turns == n - 1) break; int tar = v[cur].ss; int lb = 0, rb = n - 1; while (lb < rb) { int mid = (lb + rb + 1) >> 1; if (v[mid].ff >= tar) lb = mid; else rb = mid - 1; } int pos = lb; set<int>::iterator it = s.upper_bound(pos); if (it == s.begin()) { ans = 1; break; } cur = *(--it); } if (!ans) return 0; } return 1; } #undef int
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...