Submission #600790

# Submission time Handle Problem Language Result Execution time Memory
600790 2022-07-21T07:50:01 Z 이동현(#8470) Long Distance Coach (JOI17_coach) C++17
100 / 100
378 ms 29984 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int NS = (int)2e5 + 4;
int x, n, m, w, t;
int r[NS];
int s[NS];
vector<int> peo[NS];
int dp[NS];
int A[NS], B[NS];

vector<int> line[NS];
int lineN, f;

double cross(vector<int> x, vector<int> y){
    return (double)(y[1] - x[1]) / (x[0] - y[0]);
}

void push(int a, int b){
    while(lineN - f >= 2 && cross(line[lineN - 1], line[lineN - 2]) >= cross({a, b}, line[lineN - 1])) --lineN;
    line[lineN++] = {a, b};
}

int get(int x){
    if(f == lineN) return (int)1e18;
    int low = f, high = lineN - 1, mid;
    while(low < high){
        mid = low + high >> 1;
        if(mid + 1 < lineN && cross(line[mid + 1], line[mid]) <= x){
            low = mid + 1;
        }
        else{
            high = mid;
        }
    }
    return line[low][0] * x + line[low][1];
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> x >> n >> m >> w >> t;
    for(int i = 1; i <= n; ++i){
        cin >> s[i];
    }
    ++n; s[n] = x;
    for(int i = 1; i <= m; ++i){
        peo[i].resize(2);
        cin >> peo[i][0] >> peo[i][1];
    }
    sort(s + 1, s + n + 1, [&](int&x, int&y){return x % t < y % t;});
    sort(peo + 1, peo + m + 1);
    int pp = 0;
    for(int i = 1; i <= n; ++i){
        while(pp + 1 <= m && peo[pp + 1][0] < s[i] % t){
            ++pp;
        }
        r[i] = pp;
    }
    auto eat = [&](int all, int me)->int{
        if(all >= me) return (all - me) / t + 1;
        return 0;
    };
    for(int i = 1; i <= m; ++i){
        A[i] = w * eat(x, peo[i][0]);
        A[i] += A[i - 1];
        B[i] = peo[i][1] - w * eat(x, peo[i][0]);
        B[i] += B[i - 1];
    }
    int ans = A[m];
    int ikmn = 0;
    for(int j = 0; j < r[1]; ++j){
        push(-j, ikmn - B[j]);
    }
    for(int i = 1; i <= n; ++i){
        int X = w * (s[i] / t);
        dp[i] = get(X) + X * r[i] + A[r[i]] + B[r[i]];
        dp[i] = min(dp[i], ikmn + A[r[i]]);
        ikmn = min(ikmn, dp[i] - A[r[i]]);
        if(i < n){
            for(int j = r[i]; j < r[i + 1]; ++j){
                push(-j, ikmn - B[j]);
            }
        }

        int nval = dp[i] + A[m] - A[r[i]];
        ans = min(ans, nval);
    }
    ans += w * eat(x, 0);
    cout << ans << '\n';
    return 0;
}

Compilation message

coach.cpp: In function 'long long int get(long long int)':
coach.cpp:29:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |         mid = low + high >> 1;
      |               ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9748 KB Output is correct
4 Correct 6 ms 9680 KB Output is correct
5 Correct 8 ms 9716 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 6 ms 9680 KB Output is correct
10 Correct 7 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 8 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 6 ms 9704 KB Output is correct
15 Correct 6 ms 9748 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 6 ms 9628 KB Output is correct
18 Correct 7 ms 9724 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 5 ms 9664 KB Output is correct
22 Correct 7 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9748 KB Output is correct
4 Correct 6 ms 9680 KB Output is correct
5 Correct 8 ms 9716 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 6 ms 9680 KB Output is correct
10 Correct 7 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 8 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 6 ms 9704 KB Output is correct
15 Correct 6 ms 9748 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 6 ms 9628 KB Output is correct
18 Correct 7 ms 9724 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 5 ms 9664 KB Output is correct
22 Correct 7 ms 9684 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 8 ms 9684 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9728 KB Output is correct
27 Correct 7 ms 9684 KB Output is correct
28 Correct 7 ms 9684 KB Output is correct
29 Correct 8 ms 9704 KB Output is correct
30 Correct 7 ms 9684 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 7 ms 9668 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9744 KB Output is correct
36 Correct 7 ms 9684 KB Output is correct
37 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9748 KB Output is correct
4 Correct 6 ms 9680 KB Output is correct
5 Correct 8 ms 9716 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 6 ms 9680 KB Output is correct
10 Correct 7 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 8 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 6 ms 9704 KB Output is correct
15 Correct 6 ms 9748 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 6 ms 9628 KB Output is correct
18 Correct 7 ms 9724 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 5 ms 9664 KB Output is correct
22 Correct 7 ms 9684 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 8 ms 9684 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9728 KB Output is correct
27 Correct 7 ms 9684 KB Output is correct
28 Correct 7 ms 9684 KB Output is correct
29 Correct 8 ms 9704 KB Output is correct
30 Correct 7 ms 9684 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 7 ms 9668 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9744 KB Output is correct
36 Correct 7 ms 9684 KB Output is correct
37 Correct 6 ms 9684 KB Output is correct
38 Correct 10 ms 9824 KB Output is correct
39 Correct 10 ms 9888 KB Output is correct
40 Correct 11 ms 9884 KB Output is correct
41 Correct 9 ms 9836 KB Output is correct
42 Correct 8 ms 9812 KB Output is correct
43 Correct 9 ms 9884 KB Output is correct
44 Correct 10 ms 9824 KB Output is correct
45 Correct 8 ms 9884 KB Output is correct
46 Correct 8 ms 9900 KB Output is correct
47 Correct 9 ms 9812 KB Output is correct
48 Correct 8 ms 9812 KB Output is correct
49 Correct 9 ms 9812 KB Output is correct
50 Correct 8 ms 9812 KB Output is correct
51 Correct 9 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9728 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9748 KB Output is correct
4 Correct 6 ms 9680 KB Output is correct
5 Correct 8 ms 9716 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 6 ms 9680 KB Output is correct
10 Correct 7 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 8 ms 9684 KB Output is correct
13 Correct 7 ms 9684 KB Output is correct
14 Correct 6 ms 9704 KB Output is correct
15 Correct 6 ms 9748 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 6 ms 9628 KB Output is correct
18 Correct 7 ms 9724 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 6 ms 9684 KB Output is correct
21 Correct 5 ms 9664 KB Output is correct
22 Correct 7 ms 9684 KB Output is correct
23 Correct 6 ms 9684 KB Output is correct
24 Correct 8 ms 9684 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 6 ms 9728 KB Output is correct
27 Correct 7 ms 9684 KB Output is correct
28 Correct 7 ms 9684 KB Output is correct
29 Correct 8 ms 9704 KB Output is correct
30 Correct 7 ms 9684 KB Output is correct
31 Correct 6 ms 9684 KB Output is correct
32 Correct 7 ms 9668 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 5 ms 9684 KB Output is correct
35 Correct 5 ms 9744 KB Output is correct
36 Correct 7 ms 9684 KB Output is correct
37 Correct 6 ms 9684 KB Output is correct
38 Correct 10 ms 9824 KB Output is correct
39 Correct 10 ms 9888 KB Output is correct
40 Correct 11 ms 9884 KB Output is correct
41 Correct 9 ms 9836 KB Output is correct
42 Correct 8 ms 9812 KB Output is correct
43 Correct 9 ms 9884 KB Output is correct
44 Correct 10 ms 9824 KB Output is correct
45 Correct 8 ms 9884 KB Output is correct
46 Correct 8 ms 9900 KB Output is correct
47 Correct 9 ms 9812 KB Output is correct
48 Correct 8 ms 9812 KB Output is correct
49 Correct 9 ms 9812 KB Output is correct
50 Correct 8 ms 9812 KB Output is correct
51 Correct 9 ms 9812 KB Output is correct
52 Correct 308 ms 23660 KB Output is correct
53 Correct 287 ms 23764 KB Output is correct
54 Correct 244 ms 23700 KB Output is correct
55 Correct 249 ms 23692 KB Output is correct
56 Correct 285 ms 23792 KB Output is correct
57 Correct 240 ms 23780 KB Output is correct
58 Correct 279 ms 23720 KB Output is correct
59 Correct 283 ms 23684 KB Output is correct
60 Correct 246 ms 23792 KB Output is correct
61 Correct 292 ms 23680 KB Output is correct
62 Correct 242 ms 23680 KB Output is correct
63 Correct 378 ms 29984 KB Output is correct
64 Correct 159 ms 25092 KB Output is correct
65 Correct 342 ms 25160 KB Output is correct
66 Correct 302 ms 25108 KB Output is correct
67 Correct 349 ms 25200 KB Output is correct
68 Correct 365 ms 25088 KB Output is correct
69 Correct 302 ms 25092 KB Output is correct
70 Correct 347 ms 25200 KB Output is correct
71 Correct 325 ms 25112 KB Output is correct
72 Correct 318 ms 25176 KB Output is correct
73 Correct 356 ms 25096 KB Output is correct
74 Correct 327 ms 25192 KB Output is correct
75 Correct 359 ms 25108 KB Output is correct
76 Correct 298 ms 25192 KB Output is correct
77 Correct 265 ms 25092 KB Output is correct
78 Correct 326 ms 25196 KB Output is correct
79 Correct 348 ms 25136 KB Output is correct
80 Correct 285 ms 25112 KB Output is correct