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;
int n;
ll dp[1<<16][16];
int s[200100];
int t[200100];
long long plan_roller_coaster(std::vector<int> S, std::vector<int> T){
n = S.size();
for(int i = 0; i < n; i++){
s[i] = S[i];
t[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]));
if(dp[y][j] < inf){
}
}
}
}
}
}
}
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 t[i] < t[j];
});
for(int i = 1; i < n; i++){
if(s[ord[i]] < t[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... |