답안 #49365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49365 2018-05-27T15:35:14 Z SpaimaCarpatilor Long Distance Coach (JOI17_coach) C++17
71 / 100
2000 ms 17476 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 || 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

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);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 772 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 2 ms 796 KB Output is correct
10 Correct 2 ms 800 KB Output is correct
11 Correct 2 ms 804 KB Output is correct
12 Correct 2 ms 808 KB Output is correct
13 Correct 2 ms 812 KB Output is correct
14 Correct 3 ms 856 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 3 ms 900 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 3 ms 908 KB Output is correct
19 Correct 2 ms 912 KB Output is correct
20 Correct 2 ms 916 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 772 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 2 ms 796 KB Output is correct
10 Correct 2 ms 800 KB Output is correct
11 Correct 2 ms 804 KB Output is correct
12 Correct 2 ms 808 KB Output is correct
13 Correct 2 ms 812 KB Output is correct
14 Correct 3 ms 856 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 3 ms 900 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 3 ms 908 KB Output is correct
19 Correct 2 ms 912 KB Output is correct
20 Correct 2 ms 916 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 3 ms 928 KB Output is correct
24 Correct 2 ms 932 KB Output is correct
25 Correct 3 ms 936 KB Output is correct
26 Correct 3 ms 1068 KB Output is correct
27 Correct 3 ms 1068 KB Output is correct
28 Correct 2 ms 1068 KB Output is correct
29 Correct 2 ms 1068 KB Output is correct
30 Correct 3 ms 1068 KB Output is correct
31 Correct 2 ms 1068 KB Output is correct
32 Correct 3 ms 1068 KB Output is correct
33 Correct 2 ms 1068 KB Output is correct
34 Correct 3 ms 1068 KB Output is correct
35 Correct 3 ms 1068 KB Output is correct
36 Correct 3 ms 1068 KB Output is correct
37 Correct 3 ms 1068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 772 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 2 ms 796 KB Output is correct
10 Correct 2 ms 800 KB Output is correct
11 Correct 2 ms 804 KB Output is correct
12 Correct 2 ms 808 KB Output is correct
13 Correct 2 ms 812 KB Output is correct
14 Correct 3 ms 856 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 3 ms 900 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 3 ms 908 KB Output is correct
19 Correct 2 ms 912 KB Output is correct
20 Correct 2 ms 916 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 3 ms 928 KB Output is correct
24 Correct 2 ms 932 KB Output is correct
25 Correct 3 ms 936 KB Output is correct
26 Correct 3 ms 1068 KB Output is correct
27 Correct 3 ms 1068 KB Output is correct
28 Correct 2 ms 1068 KB Output is correct
29 Correct 2 ms 1068 KB Output is correct
30 Correct 3 ms 1068 KB Output is correct
31 Correct 2 ms 1068 KB Output is correct
32 Correct 3 ms 1068 KB Output is correct
33 Correct 2 ms 1068 KB Output is correct
34 Correct 3 ms 1068 KB Output is correct
35 Correct 3 ms 1068 KB Output is correct
36 Correct 3 ms 1068 KB Output is correct
37 Correct 3 ms 1068 KB Output is correct
38 Correct 27 ms 1136 KB Output is correct
39 Correct 49 ms 1224 KB Output is correct
40 Correct 51 ms 1244 KB Output is correct
41 Correct 27 ms 1312 KB Output is correct
42 Correct 25 ms 1324 KB Output is correct
43 Correct 23 ms 1332 KB Output is correct
44 Correct 28 ms 1528 KB Output is correct
45 Correct 25 ms 1528 KB Output is correct
46 Correct 46 ms 1536 KB Output is correct
47 Correct 46 ms 1544 KB Output is correct
48 Correct 25 ms 1552 KB Output is correct
49 Correct 35 ms 1668 KB Output is correct
50 Correct 25 ms 1716 KB Output is correct
51 Correct 29 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 772 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 2 ms 796 KB Output is correct
10 Correct 2 ms 800 KB Output is correct
11 Correct 2 ms 804 KB Output is correct
12 Correct 2 ms 808 KB Output is correct
13 Correct 2 ms 812 KB Output is correct
14 Correct 3 ms 856 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 3 ms 900 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 3 ms 908 KB Output is correct
19 Correct 2 ms 912 KB Output is correct
20 Correct 2 ms 916 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 924 KB Output is correct
23 Correct 3 ms 928 KB Output is correct
24 Correct 2 ms 932 KB Output is correct
25 Correct 3 ms 936 KB Output is correct
26 Correct 3 ms 1068 KB Output is correct
27 Correct 3 ms 1068 KB Output is correct
28 Correct 2 ms 1068 KB Output is correct
29 Correct 2 ms 1068 KB Output is correct
30 Correct 3 ms 1068 KB Output is correct
31 Correct 2 ms 1068 KB Output is correct
32 Correct 3 ms 1068 KB Output is correct
33 Correct 2 ms 1068 KB Output is correct
34 Correct 3 ms 1068 KB Output is correct
35 Correct 3 ms 1068 KB Output is correct
36 Correct 3 ms 1068 KB Output is correct
37 Correct 3 ms 1068 KB Output is correct
38 Correct 27 ms 1136 KB Output is correct
39 Correct 49 ms 1224 KB Output is correct
40 Correct 51 ms 1244 KB Output is correct
41 Correct 27 ms 1312 KB Output is correct
42 Correct 25 ms 1324 KB Output is correct
43 Correct 23 ms 1332 KB Output is correct
44 Correct 28 ms 1528 KB Output is correct
45 Correct 25 ms 1528 KB Output is correct
46 Correct 46 ms 1536 KB Output is correct
47 Correct 46 ms 1544 KB Output is correct
48 Correct 25 ms 1552 KB Output is correct
49 Correct 35 ms 1668 KB Output is correct
50 Correct 25 ms 1716 KB Output is correct
51 Correct 29 ms 1772 KB Output is correct
52 Execution timed out 2059 ms 17476 KB Time limit exceeded
53 Halted 0 ms 0 KB -