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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9 + 100;
const ll INF = 1e18 + 100;
int n;
ll dp[1<<16][16];
int a[200100];
int b[200100];
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t){
n = s.size();
for(int i = 0; i < n; i++){
a[i] = s[i];
b[i] = t[i];
}
if(n <= 16){
for(int x = 0; x < (1<<n); x++){
fill(dp[x], dp[x] + n, INF);
if(!x) continue;
if(__builtin_popcount(x) == 1){
for(int i = 0; i < n; i++){
if(x & (1<<i)) dp[x][i] = 0;
}
} else{
for(int i = 0; i < n; i++){
if(x & (1<<i)){
int y = x ^ (1<<i);
for(int j = 0; j < n; j++){
if(y & (1<<j)){
dp[x][i] = min(dp[x][i], dp[y][j] + max(0, t[j] - s[i]));
}
}
}
}
}
}
return *min_element(dp[(1<<n)-1], dp[(1<<n)-1] + n);
} else{
vector<int> ord;
for(int i = 0; i < n; i++){
ord.push_back(i);
}
sort(ord.begin(), ord.end(), [](int i, int j){
return a[i] < a[j];
});
for(int i = 1; i < n; i++){
if(a[ord[i]] < b[ord[i-1]]) return 1;
}
return 0;
}
}
# | 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... |