Submission #993170

#TimeUsernameProblemLanguageResultExecution timeMemory
993170boris_mihovTrain (APIO24_train)C++17
0 / 100
60 ms26196 KiB
#include "train.h" #include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> #include <queue> typedef long long llong; const int MAXN = 100000 + 10; const llong INF = 4e18; const int INTINF = 2e9; int n, m, w; struct Edge { int from; int to; int cost; int begTime; int endTime; }; Edge edges[MAXN]; struct Interval { int from, to, cost; }; int father[MAXN]; std::vector <std::pair <int,int>> intervals; std::vector <std::pair <int,llong>> g[2 * MAXN]; std::vector <int> begining[MAXN]; std::vector <int> ending[MAXN]; llong dist[MAXN]; bool vis[MAXN]; int t[MAXN]; 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) { n = N; m = M; w = W; for (int i = 0 ; i < m ; ++i) { X[i]++; Y[i]++; edges[i + 1] = {X[i], Y[i], C[i], A[i], B[i]}; begining[X[i]].push_back(i + 1); ending[Y[i]].push_back(i + 1); } for (int i = 1 ; i <= n ; ++i) { t[i] = T[i - 1]; } for (int i = 0 ; i < w ; ++i) { intervals.push_back({L[i], R[i]}); } int cnt = m; for (int i = 1 ; i <= n ; ++i) { std::sort(ending[i].begin(), ending[i].end(), [&](int x, int y) { return edges[x].endTime < edges[y].endTime; }); std::sort(begining[i].begin(), begining[i].end(), [&](int x, int y) { return edges[x].begTime < edges[y].begTime; }); for (int j = 0 ; j < begining[i].size() ; ++j) { father[begining[i][j]] = ++cnt; g[father[begining[i][j]]].push_back({begining[i][j], edges[begining[i][j]].cost}); } for (int j = 0 ; j + 1 < begining[i].size() ; ++j) { g[father[begining[i][j]]].push_back({father[begining[i][j + 1]], 0}); } int ptr = begining[i].size(); for (int j = (int)ending[i].size() - 1 ; j >= 0 ; --j) { while (ptr > 0 && edges[begining[i][ptr - 1]].begTime >= edges[ending[i][j]].endTime) { ptr--; } if (ptr < begining[i].size()) g[ending[i][j]].push_back({father[begining[i][ptr]], 0}); } } std::fill(dist + 1, dist + 1 + m, INF); std::priority_queue <std::pair <llong,int>> pq; for (const int &idx : begining[1]) { // int count = 0; // for (const auto &[l, r] : intervals) // { // count += (r < edges[idx].begTime); // } dist[idx] = edges[idx].cost;// + 1LL * count * t[1]; pq.push({-dist[idx], idx}); } while (pq.size()) { auto [d, node] = pq.top(); pq.pop(); if (vis[node]) { continue; } vis[node] = true; for (const auto &[u, ed] : g[node]) { if (dist[u] > dist[node] + ed) { dist[u] = dist[node] + ed; pq.push({-dist[u], u}); } } } llong min = INF; for (const auto &idx : ending[n]) { // int count = 0; // for (const auto &[l, r] : intervals) // { // count += (edges[idx].endTime < l); // } min = std::min(min, dist[idx]); } if (min == INF) return -1; return min; }

Compilation message (stderr)

train.cpp: In function 'long long int solve(int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:76:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int j = 0 ; j < begining[i].size() ; ++j)
      |                          ~~^~~~~~~~~~~~~~~~~~~~
train.cpp:82:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for (int j = 0 ; j + 1 < begining[i].size() ; ++j)
      |                          ~~~~~~^~~~~~~~~~~~~~~~~~~~
train.cpp:95:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             if (ptr < begining[i].size()) g[ending[i][j]].push_back({father[begining[i][ptr]], 0});
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...