답안 #211250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211250 2020-03-19T18:43:40 Z Alexa2001 Long Distance Coach (JOI17_coach) C++17
100 / 100
197 ms 18476 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll inf = 1e19;

const int Nmax = 2e5 + 5;
const ll eps = 1e-6;

int n, m, T, W, nr;
ll S[Nmax], P[Nmax];
int st[Nmax];

ll sumC[Nmax], need[Nmax], C[Nmax], dp[Nmax], sep[Nmax], coef[Nmax];
ll X;


void read()
{
    cin >> X >> n >> m >> W >> T;

    int i;
    for(i=1; i<=n; ++i) cin >> S[i];

    vector<pair<ll,int>> a(m+1);
    for(i=1; i<=m; ++i) cin >> a[i].first >> a[i].second;

    sort(a.begin() + 1, a.end());
    for(i=1; i<=m; ++i)
        P[i] = a[i].first, C[i] = a[i].second;
}

void prec()
{
    int i;
    for(i=1; i<=m; ++i)
    {
        sumC[i] = sumC[i-1] + C[i];
        need[i] = (X - P[i]) / T + 1;
    }

    for(i=1; i<=m; ++i) sep[i] = inf;

    S[++n] = X;
    for(i=1; i<=n; ++i)
    {
        int pos = lower_bound(P+1, P+m+1, S[i] % T) - P - 1;
        if(pos)
            sep[pos] = min<ll>(sep[pos], S[i] / T);
    }
}


namespace H
{
    static ll a[Nmax], b[Nmax];
    int nr = 0;

    long double meet(int x, int y)
    {
        return (long double) (b[x] - b[y]) / (a[y] - a[x]);
    }

    bool bad(int x, int y, int z)
    {
        return meet(x, y) - meet(y, z) < -eps;
    }

    void add(ll A, ll B)
    {
        a[0] = A; b[0] = B;
        while(nr >= 2 && bad(nr - 1, nr, 0)) --nr;
        a[++nr] = A; b[nr] = B;
        a[0] = b[0] = 0;
    }

    ll query(ll x)
    {
        int st = 1, dr = nr-1, mid;

        while(st <= dr)
        {
            mid = (st + dr) / 2;
            if(meet(mid, mid+1) - x > eps) st = mid + 1;
                else dr = mid - 1;
        }

        return a[st] * x + b[st];
    }
};

void solve()
{
    int i;

    H :: add(0, 0);

    for(i=1; i<=m; ++i)
    {
        dp[i] = dp[i-1] + need[i] * W;

        if(sep[i] != inf)
            dp[i] = min( dp[i], H :: query(-sep[i] * W) + sep[i] * i * W + sumC[i] );

        H :: add(i, dp[i] - sumC[i]);
    }

    cout << dp[m] + W * (X / T + 1) << '\n';
}

int main()
{
  //  freopen("input", "r", stdin);
   // freopen("output", "w", stdout);
    cin.sync_with_stdio(false); cin.tie(0);

    read();
    prec();
    solve();

    return 0;
}

Compilation message

coach.cpp:6:16: warning: overflow in implicit constant conversion [-Woverflow]
 const ll inf = 1e19;
                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 640 KB Output is correct
39 Correct 6 ms 640 KB Output is correct
40 Correct 6 ms 640 KB Output is correct
41 Correct 6 ms 640 KB Output is correct
42 Correct 6 ms 640 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 7 ms 640 KB Output is correct
45 Correct 6 ms 640 KB Output is correct
46 Correct 6 ms 640 KB Output is correct
47 Correct 6 ms 640 KB Output is correct
48 Correct 6 ms 640 KB Output is correct
49 Correct 6 ms 640 KB Output is correct
50 Correct 6 ms 640 KB Output is correct
51 Correct 6 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 640 KB Output is correct
39 Correct 6 ms 640 KB Output is correct
40 Correct 6 ms 640 KB Output is correct
41 Correct 6 ms 640 KB Output is correct
42 Correct 6 ms 640 KB Output is correct
43 Correct 6 ms 512 KB Output is correct
44 Correct 7 ms 640 KB Output is correct
45 Correct 6 ms 640 KB Output is correct
46 Correct 6 ms 640 KB Output is correct
47 Correct 6 ms 640 KB Output is correct
48 Correct 6 ms 640 KB Output is correct
49 Correct 6 ms 640 KB Output is correct
50 Correct 6 ms 640 KB Output is correct
51 Correct 6 ms 640 KB Output is correct
52 Correct 151 ms 16948 KB Output is correct
53 Correct 137 ms 17072 KB Output is correct
54 Correct 143 ms 17072 KB Output is correct
55 Correct 150 ms 16820 KB Output is correct
56 Correct 154 ms 16816 KB Output is correct
57 Correct 153 ms 16560 KB Output is correct
58 Correct 170 ms 17024 KB Output is correct
59 Correct 150 ms 16784 KB Output is correct
60 Correct 197 ms 16556 KB Output is correct
61 Correct 148 ms 16896 KB Output is correct
62 Correct 152 ms 16560 KB Output is correct
63 Correct 114 ms 18476 KB Output is correct
64 Correct 117 ms 17240 KB Output is correct
65 Correct 117 ms 17068 KB Output is correct
66 Correct 118 ms 17072 KB Output is correct
67 Correct 125 ms 17048 KB Output is correct
68 Correct 123 ms 17068 KB Output is correct
69 Correct 151 ms 16836 KB Output is correct
70 Correct 156 ms 16816 KB Output is correct
71 Correct 158 ms 16944 KB Output is correct
72 Correct 152 ms 16816 KB Output is correct
73 Correct 157 ms 16812 KB Output is correct
74 Correct 158 ms 16816 KB Output is correct
75 Correct 159 ms 17072 KB Output is correct
76 Correct 165 ms 17068 KB Output is correct
77 Correct 159 ms 18348 KB Output is correct
78 Correct 157 ms 17072 KB Output is correct
79 Correct 156 ms 16420 KB Output is correct
80 Correct 153 ms 16560 KB Output is correct