제출 #299419

#제출 시각아이디문제언어결과실행 시간메모리
299419sandovalRoller Coaster Railroad (IOI16_railroad)C++11
34 / 100
96 ms23416 KiB
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int,int>;
using ll = long long;

constexpr int MAXN = 16;
constexpr ll INF = 1LL<<58;
ll memo[MAXN][1<<MAXN];

ll dp(int u, int bm, const vector<int>& s, const vector<int>& t) {
  bm ^= (1<<u);
  if (bm == 0) return 0;
  ll& ans = memo[u][bm];
  if (ans != -1) return ans;
  ans = INF;

  for (int j = 0; j < (int)s.size(); ++j) {
    if ((bm>>j)&1) {
      ans = min(ans, dp(j, bm, s, t) + max(0, t[u] - s[j]));
    }
  }
  return ans;
}

ll plan_roller_coaster(vector<int> s, vector<int> t) {
  memset(memo, -1, sizeof memo);
  ll ans = INF;
  const int n = (int)s.size();
  for (int i = 0; i < n; ++i) {
    ans = min(ans, dp(i, (1<<n)-1, s, t));
  }
  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...