Submission #363531

# Submission time Handle Problem Language Result Execution time Memory
363531 2021-02-06T13:05:12 Z denkendoemeer Long Distance Coach (JOI17_coach) C++14
100 / 100
198 ms 20572 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[200005],poz[200005],d[200005],c[200005],c2[200005];
pair<ll,ll>a[200005],b[200005];
struct cht
{
    struct line
    {
        ll x,y;
    };
    vector<line>aux;
    int u;
    long double crossp(line a,line b)
    {
        return (long double)(b.y-a.y)/(long double)(a.x-b.x);
    }
    void add(ll a,ll b)
    {
        line l={a,b};
        while(u>1 && crossp(aux[u-2],aux[u-1])>crossp(aux[u-2],l)){
            aux.pop_back();
            u--;
        }
        aux.push_back(l);
        u++;
    }
    ll query(ll x)
    {
        int st=0,dr=u-2,mij;
        while(st<=dr){
            mij=(st+dr)/2;
            if (crossp(aux[mij],aux[mij+1])<=x)
                st=mij+1;
            else
                dr=mij-1;
        }
        return aux[st].x*x+aux[st].y;
    }
}cht;
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    ll x,w,t;
    int n,m,i;
    scanf("%lld%d%d%lld%lld",&x,&n,&m,&w,&t);
    b[0]={x%t,x/t};
    for(i=1;i<=n;i++){
        ll x;
        scanf("%lld",&x);
        b[i]={x%t,x/t};
    }
    for(i=1;i<=m;i++)
        scanf("%lld%lld",&a[i].first,&a[i].second);
    sort(a+1,a+m+1);
    c2[0]=(x+t-1)/t;
    for(i=1;i<=m;i++){
        c[i]=c[i-1]+a[i].second;
        if (a[i].first<x%t)
            c2[i]=c2[i-1]+x/t+1;
        else
            c2[i]=c2[i-1]+x/t;
    }
    for(i=1;i<=m;i++)
        poz[i]=(x+t-1)/t+1;
    for(i=0;i<=n;i++){
        int aux=upper_bound(a+1,a+m+1,b[i])-a-1;
        poz[aux]=min(poz[aux],b[i].second);
    }
    cht.add(0,-c2[0]*w);
    for(i=1;i<=m;i++){
        dp[i]=max(dp[i-1],cht.query(poz[i])+(c2[i]-i*poz[i])*w-c[i]);
        cht.add(w*i,dp[i]+c[i]-c2[i]*w);
    }
    printf("%lld\n",c2[m]*w-dp[m]);
return 0;
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     scanf("%lld%d%d%lld%lld",&x,&n,&m,&w,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%lld",&x);
      |         ~~~~~^~~~~~~~~~~
coach.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |         scanf("%lld%lld",&a[i].first,&a[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 492 KB Output is correct
46 Correct 2 ms 620 KB Output is correct
47 Correct 2 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 2 ms 620 KB Output is correct
50 Correct 2 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 2 ms 492 KB Output is correct
39 Correct 2 ms 492 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 492 KB Output is correct
46 Correct 2 ms 620 KB Output is correct
47 Correct 2 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 2 ms 620 KB Output is correct
50 Correct 2 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 170 ms 18556 KB Output is correct
53 Correct 117 ms 18576 KB Output is correct
54 Correct 165 ms 18724 KB Output is correct
55 Correct 156 ms 18532 KB Output is correct
56 Correct 156 ms 18480 KB Output is correct
57 Correct 158 ms 18156 KB Output is correct
58 Correct 172 ms 18668 KB Output is correct
59 Correct 152 ms 18404 KB Output is correct
60 Correct 158 ms 18152 KB Output is correct
61 Correct 174 ms 18660 KB Output is correct
62 Correct 155 ms 18408 KB Output is correct
63 Correct 113 ms 20572 KB Output is correct
64 Correct 110 ms 18668 KB Output is correct
65 Correct 118 ms 18668 KB Output is correct
66 Correct 115 ms 18796 KB Output is correct
67 Correct 127 ms 18752 KB Output is correct
68 Correct 123 ms 18668 KB Output is correct
69 Correct 175 ms 18412 KB Output is correct
70 Correct 158 ms 18284 KB Output is correct
71 Correct 170 ms 18428 KB Output is correct
72 Correct 198 ms 18412 KB Output is correct
73 Correct 166 ms 18412 KB Output is correct
74 Correct 163 ms 18496 KB Output is correct
75 Correct 165 ms 18796 KB Output is correct
76 Correct 167 ms 18540 KB Output is correct
77 Correct 166 ms 19936 KB Output is correct
78 Correct 158 ms 18540 KB Output is correct
79 Correct 160 ms 18028 KB Output is correct
80 Correct 158 ms 18028 KB Output is correct