Submission #282630

# Submission time Handle Problem Language Result Execution time Memory
282630 2020-08-24T16:20:46 Z DystoriaX Long Distance Coach (JOI17_coach) C++14
71 / 100
2000 ms 14292 KB
#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

long long x, t;
int n, m, w;

long long s[200010];
pair<long long, int> v[200010];
long long pos[200010], spos[200010];
long long dp[200010], ans;

long long Get(long long x){
    return x - (x % t);
}

int main(){
    scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);

    for(int i = 1; i <= n; i++) scanf("%lld", &s[i]);

    for(int i = 1; i <= m; i++) scanf("%lld%d", &v[i].fi, &v[i].se), pos[i] = v[i].fi;

    sort(v + 1, v + 1 + m);
    sort(pos + 1, pos + 1 + m);

    memset(spos, -1, sizeof(spos));
    
    s[n + 1] = x;
    for(int i = 1; i <= n + 1; i++){
        int id = upper_bound(pos + 1, pos + 1 + m, s[i] % t) - pos;
        --id;

        if(spos[id] == -1 || spos[id] > s[i]) spos[id] = s[i];
    }

    for(int i = 0; i <= m; i++)
        ans += (x - v[i].fi) / t + 1;
    
    ans *= w;

    for(int i = 1; i <= m; i++){
        dp[i] = dp[i - 1];

        if(spos[i] == -1) continue;

        long long cost = 0;
        for(int k = i - 1; k >= 0; k--){
            cost += -((x - (Get(spos[i]) + v[k + 1].fi)) / t + 1) * w + v[k + 1].se;

            dp[i] = min(dp[i], dp[k] + cost);
        }
    }

    printf("%lld\n", ans + dp[m]);

    return 0;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:23:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     for(int i = 1; i <= n; i++) scanf("%lld", &s[i]);
      |                                 ~~~~~^~~~~~~~~~~~~~~
coach.cpp:25:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     for(int i = 1; i <= m; i++) scanf("%lld%d", &v[i].fi, &v[i].se), pos[i] = v[i].fi;
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 1 ms 1920 KB Output is correct
10 Correct 1 ms 1920 KB Output is correct
11 Correct 1 ms 1920 KB Output is correct
12 Correct 1 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 1 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 1 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 1 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 1 ms 1920 KB Output is correct
10 Correct 1 ms 1920 KB Output is correct
11 Correct 1 ms 1920 KB Output is correct
12 Correct 1 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 1 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 1 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 1 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1972 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 1 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 1 ms 1920 KB Output is correct
31 Correct 2 ms 1920 KB Output is correct
32 Correct 2 ms 1920 KB Output is correct
33 Correct 2 ms 1920 KB Output is correct
34 Correct 2 ms 2048 KB Output is correct
35 Correct 1 ms 1920 KB Output is correct
36 Correct 1 ms 1920 KB Output is correct
37 Correct 2 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 1 ms 1920 KB Output is correct
10 Correct 1 ms 1920 KB Output is correct
11 Correct 1 ms 1920 KB Output is correct
12 Correct 1 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 1 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 1 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 1 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1972 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 1 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 1 ms 1920 KB Output is correct
31 Correct 2 ms 1920 KB Output is correct
32 Correct 2 ms 1920 KB Output is correct
33 Correct 2 ms 1920 KB Output is correct
34 Correct 2 ms 2048 KB Output is correct
35 Correct 1 ms 1920 KB Output is correct
36 Correct 1 ms 1920 KB Output is correct
37 Correct 2 ms 1920 KB Output is correct
38 Correct 10 ms 2048 KB Output is correct
39 Correct 18 ms 2048 KB Output is correct
40 Correct 24 ms 2048 KB Output is correct
41 Correct 10 ms 2048 KB Output is correct
42 Correct 11 ms 2048 KB Output is correct
43 Correct 10 ms 2048 KB Output is correct
44 Correct 14 ms 2048 KB Output is correct
45 Correct 10 ms 2048 KB Output is correct
46 Correct 20 ms 2048 KB Output is correct
47 Correct 19 ms 2048 KB Output is correct
48 Correct 12 ms 2048 KB Output is correct
49 Correct 11 ms 2048 KB Output is correct
50 Correct 10 ms 2048 KB Output is correct
51 Correct 10 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1920 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 1 ms 1920 KB Output is correct
5 Correct 1 ms 1920 KB Output is correct
6 Correct 1 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 1 ms 1920 KB Output is correct
9 Correct 1 ms 1920 KB Output is correct
10 Correct 1 ms 1920 KB Output is correct
11 Correct 1 ms 1920 KB Output is correct
12 Correct 1 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 1 ms 1920 KB Output is correct
15 Correct 1 ms 1920 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 1 ms 1920 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 1 ms 1920 KB Output is correct
20 Correct 2 ms 1920 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 1 ms 1920 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 2 ms 1920 KB Output is correct
25 Correct 2 ms 1972 KB Output is correct
26 Correct 2 ms 1920 KB Output is correct
27 Correct 1 ms 1920 KB Output is correct
28 Correct 1 ms 1920 KB Output is correct
29 Correct 2 ms 1920 KB Output is correct
30 Correct 1 ms 1920 KB Output is correct
31 Correct 2 ms 1920 KB Output is correct
32 Correct 2 ms 1920 KB Output is correct
33 Correct 2 ms 1920 KB Output is correct
34 Correct 2 ms 2048 KB Output is correct
35 Correct 1 ms 1920 KB Output is correct
36 Correct 1 ms 1920 KB Output is correct
37 Correct 2 ms 1920 KB Output is correct
38 Correct 10 ms 2048 KB Output is correct
39 Correct 18 ms 2048 KB Output is correct
40 Correct 24 ms 2048 KB Output is correct
41 Correct 10 ms 2048 KB Output is correct
42 Correct 11 ms 2048 KB Output is correct
43 Correct 10 ms 2048 KB Output is correct
44 Correct 14 ms 2048 KB Output is correct
45 Correct 10 ms 2048 KB Output is correct
46 Correct 20 ms 2048 KB Output is correct
47 Correct 19 ms 2048 KB Output is correct
48 Correct 12 ms 2048 KB Output is correct
49 Correct 11 ms 2048 KB Output is correct
50 Correct 10 ms 2048 KB Output is correct
51 Correct 10 ms 2048 KB Output is correct
52 Execution timed out 2061 ms 14292 KB Time limit exceeded
53 Halted 0 ms 0 KB -