제출 #595057

#제출 시각아이디문제언어결과실행 시간메모리
595057LucppRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
263 ms28432 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; set<pair<int, int>> byS; int calc(int s, int t){ byS.erase(make_pair(s, t)); if(byS.empty()) return 0; auto it = byS.lower_bound(make_pair(t, 0)); if(it == byS.end()){ byS.emplace(s, t); return -1; } int code = calc(it->first, it->second); if(code == -2) return -2; if(code == -1){ it = ++byS.lower_bound(make_pair(t, 0)); if(it == byS.end() || calc(it->first, it->second) < 0) return -2; } return 0; } ll plan_roller_coaster(vector<int> s, vector<int> t) { int n = (int)s.size(); if(n <= 16){ vector<vector<ll>> dp(1<<n, vector<ll>(n)); for(int msk=1; msk < (1<<n); msk++){ if(__builtin_popcount(msk) == 1) continue; for(int i = 0; i < n; i++){ if(!(msk & (1<<i))) continue; dp[msk][i] = INF; int m = msk^(1<<i); for(int j = 0; j < n; j++){ if(!(m & (1<<j))) continue; dp[msk][i] = min(dp[msk][i], dp[m][j] + max(0, t[j]-s[i])); } } } ll ans = INF; for(int i = 0; i < n; i++) ans = min(ans, dp[(1<<n)-1][i]); return ans; } else{ for(int i = 0; i < n; i++) byS.emplace(s[i], t[i]); int code = calc(s[0], t[0]); if(code == -1) code = calc(s[1], t[1]); if(code < 0) return 1; else 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...