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 plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
if(n<17)
{
vector<vector<long long>> dp((1<<n), vector<long long>(n,1e16));
long long kk=1;
int kkpos=0;
while(kkpos<n)
{
dp[kk][kkpos]=0;
kk=kk*2;
kkpos++;
}
for(int i=0;i<(1<<n);i++)
{
for(int j=0;j<n;j++)
{
if(((1<<j) & i)==0)
{
for(int k=0;k<n;k++)
{
if(((1<<k) & i)!=0)
{
long long distance=max((t[k]-s[j]),0);
dp[i | (1<<j)][j]=min(dp[i | (1<<j)][j],(dp[i][k] + distance));
}
}
}
}
}
long long minnimum=1e16;
for(int j=0;j<n;j++)
{
minnimum=min(minnimum,dp[(1<<n) - 1][j]);
}
return minnimum;
}
vector<pair<int,int>> ss,tt;
for(int i=0;i<n;i++)
{
tt.push_back({t[i], i});
ss.push_back({s[i], i});
}
sort(ss.rbegin(), ss.rend());
sort(tt.rbegin(), tt.rend());
int i=0;
int j=1;
while(j<n)
{
if(ss[i].second != tt[j].second)
{
if(tt[j].first > ss[i].first)
return 999;
}
else if(i != n - 1)
{
if(tt[j].first > ss[i + 1].first)
return 999;
}
i++, j++;
}
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... |