| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1333941 | ThylOne | Train (APIO24_train) | C++20 | 0 ms | 0 KiB |
#include "train.h"
#include <algorithm>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
int id, time;
bool operator<(node const& a){
return time > a.time;
}
};
struct edge{
int depart;
int arrive;
int td, ta;
int cost;
bool operator<(edge const& e){
return ta < e.ta;
}
};
const int N = 1e5;
const int OO = 1e18;
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) {
vector<edge> edges;
for(int i = 0 ; i < M; i++){
edges.push_back({X[i], Y[i], A[i], B[i],C[i]});
}
sort(edges.begin(), edges.end());
vector<vector<pair<int,int>>> min_cost(N);
vector<int> cost_from0(M, -1);
min_cost[0].emplace_back(0,0);
for(int e = 0 ; e < M ; e++){
auto &act = edges[e];
if(min_cost[act.depart].empty())continue;//pas de timing
auto it = upper_bound(min_cost[act.depart].begin(), min_cost[act.depart].end(), make_pair(act.ta+1, OO));
if(it == min_cost[act.depart].begin())continue;//toujours trop tard
it--;
cost_from0[e] = act.cost + it->second;
min_cost[act.arrive].emplace_back(act.ta,min(min_cost[act.arrive].back().second, cost_from0[e]));
}
int ans = OO;
for(int e = 0 ; e < M ; e++){
if(edges[e].arrive == N-1){
ans = min(ans, cost_from0[e]);
}
}
return (ans==OO?-1:ans);
}
