This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
long long memo[20][100000];
int n;
int arr1[20],arr2[20];
long long dp(int prev,int bm){
if (bm == (1<<n)-1) return 0;
if (memo[prev][bm] != -1) return memo[prev][bm];
memo[prev][bm] = 1e18;
for (int i = 0; i < n; i++){
if (bm & (1<<i)) continue;
int cost = max(0,arr2[prev]-arr1[i]);
memo[prev][bm] = min(memo[prev][bm],dp(i,bm+(1<<i))+cost);
}
return memo[prev][bm];
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
n = (int) s.size();
if (n > 20) return 0;
for (int i = 0; i < n; i++){
arr1[i] = s[i];
arr2[i] = t[i];
}
for (int i = 0; i < 20; i++)for (int j = 0; j < 100000; j++) memo[i][j] = -1;
long long ans = 1e18;
for (int i = 0; i < n; i++) ans = min(ans,dp(i,1<<i));
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |