Submission #49367

# Submission time Handle Problem Language Result Execution time Memory
49367 2018-05-27T15:40:24 Z SpaimaCarpatilor Long Distance Coach (JOI17_coach) C++17
0 / 100
3 ms 724 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 --;
    ///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) break;/// || station[pntr].first > passenger[i].first should be wrong without that condition
        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

coach.cpp: In function 'void read()':
coach.cpp:20:66: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf ("%d %d", &passenger[i].first, &passenger[i].second);
                         ~~~~~~~~~~~~~~~~~~~                      ^
coach.cpp:13:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%lld %d %d %d %d", &X, &N, &M, &W, &T);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:15:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%lld", &station[i].second), station[i].first = station[i].second % T;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:20:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d %d", &passenger[i].first, &passenger[i].second);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Incorrect 2 ms 724 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Incorrect 2 ms 724 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Incorrect 2 ms 724 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 652 KB Output is correct
7 Correct 2 ms 652 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Incorrect 2 ms 724 KB Output isn't correct
13 Halted 0 ms 0 KB -