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 "train.h"
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
struct train
{
int from,to;
int tin,tout;
int cost;
};
bool cmp(train x, train y)
{
return x.tin < y.tin;
}
vector<train> trains;
vector<pair<int,int>> meals;
long long dp[100005];
vector<int> meal_cost;
long long solve(int N, int M, int W, std::vector<int> T, std::vector<int> X, std::vector<int> Y,
std::vector<int> A, std::vector<int> B, std::vector<int> C, std::vector<int> L,
std::vector<int> R)
{
meal_cost = T;
for(int i=0;i<M;i++)
{
trains.push_back({X[i],Y[i],A[i],B[i],C[i]});
}
for(int i=0;i<W;i++)
{
meals.push_back({L[i],R[i]});
}
sort(trains.begin(),trains.end(),cmp);
for(int i=0;i<M;i++)
{
dp[i]=INF;
if(trains[i].from==0)
{
long long cnt=0;
for(auto [x,y]:meals)
if(y < trains[i].tin)
cnt++;
dp[i] = min(dp[i], cnt*meal_cost[trains[i].from] + trains[i].cost);
}
for(int j=0;j<i;j++)
{
if(trains[j].to == trains[i].from && trains[j].tout <= trains[i].tin)
{
long long cnt=0;
for(auto [x,y]:meals)
if(x > trains[j].tout && y < trains[i].tin)
cnt++;
dp[i] = min(dp[i], dp[j] + cnt*meal_cost[trains[i].from] + trains[i].cost);
}
}
}
long long rez=INF;
for(int i=0;i<M;i++)
{
if(trains[i].to==N-1)
{
long long cnt=0;
for(auto [x,y]:meals)
if(x > trains[i].tout)
cnt++;
rez = min(rez, dp[i] + cnt*meal_cost[N-1]);
}
}
if(rez==INF)
return -1;
else
return rez;
}
/**
dp[i] = costul minim de a parcurge o ruta care incepe la nodul 0, a.i. ultimul tren luat sa fie i (cumparam un meal doar daca e obligatoriu)
*/
# | 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... |