# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
49366 | 2018-05-27T15:39:14 Z | SpaimaCarpatilor | Long Distance Coach (JOI17_coach) | C++17 | 3 ms | 520 KB |
#include<bits/stdc++.h> using namespace std; int N, M, W, T, how[200009]; long long X, dp[200009], need[200009]; const long long INF = 1LL << 60; pair < int, long long > station[200009]; pair < long long, int > passenger[200009]; void read () { scanf ("%lld %d %d %d %d", &X, &N, &M, &W, &T); for (int i=1; i<=N; i++) scanf ("%lld", &station[i].second), station[i].first = station[i].second % T; if (X % T != 0) station[++N] = {X % T, X}; sort (station + 1, station + N + 1); for (int i=1; i<=M; i++) scanf ("%d %d", &passenger[i].first, &passenger[i].second); sort (passenger + 1, passenger + M + 1); } int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); read (); for (int i=1; i<=M; i++) need[i] = 1LL * W * ((X - passenger[i].first) / T + 1); for (int i=0; i<=M; i++) dp[i] = INF; dp[M + 1] = 1LL * W * (X / T + 1);///dp[i] = i gets there (in our case the driver) and I've already considered all those with higher residuum passenger[M + 1].first = T + 1; for (int i=M + 1; i>=1; i--) { if (dp[i] + need[i - 1] < dp[i - 1]) dp[i - 1] = dp[i] + need[i - 1], how[i - 1] = i; int pntr = N + 1; long long fastestAbort = X + 1; /*while (pntr > 1 && station[pntr - 1].first > passenger[i].first) pntr --; without this, the source should be wrong*/ ///I want to ignore those starting at pntr cause they would all abort i as well long long curr = dp[i]; for (int j=i - 1; j>=1; j--) { ///assume you've aborted all passengers in range [j, i - 1] while (pntr > 1 && station[pntr - 1].first > passenger[j].first) pntr --, fastestAbort = min (fastestAbort, station[pntr].second); if (station[pntr].first <= passenger[j].first || station[pntr].first > passenger[i].first) break; curr += passenger[j].second; if (fastestAbort > passenger[j].first) curr += 1LL * W * ((fastestAbort - passenger[j].first) / T); if (curr + need[j - 1] < dp[j - 1]) dp[j - 1] = curr + need[j - 1], how[j - 1] = i; } } printf ("%lld\n", dp[0]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 448 KB | Output is correct |
3 | Correct | 2 ms | 448 KB | Output is correct |
4 | Correct | 3 ms | 448 KB | Output is correct |
5 | Incorrect | 2 ms | 520 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 448 KB | Output is correct |
3 | Correct | 2 ms | 448 KB | Output is correct |
4 | Correct | 3 ms | 448 KB | Output is correct |
5 | Incorrect | 2 ms | 520 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 448 KB | Output is correct |
3 | Correct | 2 ms | 448 KB | Output is correct |
4 | Correct | 3 ms | 448 KB | Output is correct |
5 | Incorrect | 2 ms | 520 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 448 KB | Output is correct |
3 | Correct | 2 ms | 448 KB | Output is correct |
4 | Correct | 3 ms | 448 KB | Output is correct |
5 | Incorrect | 2 ms | 520 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |