Submission #807486

#TimeUsernameProblemLanguageResultExecution timeMemory
807486happypotatoRoller Coaster Railroad (IOI16_railroad)C++17
0 / 100
165 ms22852 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; for (int i = 0; i < n; i++) s.insert(i); int cur = n - 1; for (int turns = 0; turns < n; turns++) { s.erase(s.find(cur)); if (turns == n - 1) return 0; 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()) return 1; cur = *(--it); } } #undef int

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:50:17: warning: control reaches end of non-void function [-Wreturn-type]
   50 |  vector<pii> v(n);
      |                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...