Submission #842509

# Submission time Handle Problem Language Result Execution time Memory
842509 2023-09-03T01:47:38 Z CodePlatina Overtaking (IOI23_overtaking) C++17
100 / 100
968 ms 58212 KB
#include "overtaking.h"
#include <algorithm>
#include <iostream>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ff first
#define ss second
using namespace std;
const long long INF = (long long)2e18 + 17;

int X;
vector<int> S;
vector<pll> A;
vector<vector<pll>> B;
vector<vector<long long>> MX;
int nxt[1'000'005];

void init(int L, int N, vector<long long> T, vector<int> W, int X, int M, vector<int> S)
{
    ::X = X;
    ::S = S;
    for(int i = 0; i < N; ++i) if(W[i] > X) A.push_back({ T[i], W[i] });
    N = A.size();
    sort(A.begin(), A.end());

    B.push_back(A);
    for(int i = 1; i < M; ++i)
    {
        int t = S[i] - S[i - 1];
        vector<pll> C;
        vector<long long> D;
        long long mx = -INF;
        long long prmx = -INF;
        for(int j = 0; j < N; ++j)
        {
            if(j && B.back()[j - 1].ff < B.back()[j].ff)
                mx = max(mx, prmx), prmx = -INF;
            D.push_back(mx);
            long long cur = B.back()[j].ff + B.back()[j].ss * t;
            C.push_back({ max(mx, cur), B.back()[j].ss });
            prmx = max(prmx, cur);
        }
        D.push_back(max(mx, prmx));
        sort(C.begin(), C.end());
        B.push_back(C);
        MX.push_back(D);
    }

    for(int i = 0; i < M; ++i)
    {
        for(int j = 0; j < N; ++j)
        {
            int cur = i * N + j;
            int s = i, e = M;
            while(s + 1 < e)
            {
                int mid = s + e >> 1;
                if(j == 0 || B[mid][j - 1].ff < B[i][j].ff + 1ll * X * (S[mid] - S[i])) s = mid;
                else e = mid;
            }
            if(e < M)
                nxt[cur] = e * N + (lower_bound(B[e].begin(), B[e].end(), pll{MX[s][j], -INF}) - B[e].begin());
            else nxt[cur] = cur;
        }
    }

    for(int i = N * M - 1; i >= 0; --i) nxt[i] = nxt[nxt[i]];
}

long long arrival_time(long long Y)
{
    int M = B.size(), N = B[0].size();
    
    int ind = lower_bound(B[0].begin(), B[0].end(), pll{Y, -INF}) - B[0].begin();
    int s = 0, e = M;
    while(s + 1 < e)
    {
        int mid = s + e >> 1;
        if(ind == 0 || B[mid][ind - 1].ff < Y + 1ll * X * S[mid]) s = mid;
        else e = mid;
    }
    if(e == M) return Y + 1ll * X * S.back();

    // cout << e << endl;

    ind = e * N + (lower_bound(B[e].begin(), B[e].end(), pll{MX[s][ind], -INF}) - B[e].begin());
    ind = nxt[ind];

    int i = ind / N, j = ind % N;
    // cout << i << ' ' << j << endl;
    return B[i][j].ff + 1ll * X * (S.back() - S[i]);
}

Compilation message

overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:57:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |                 int mid = s + e >> 1;
      |                           ~~^~~
overtaking.cpp: In function 'long long int arrival_time(long long int)':
overtaking.cpp:78:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |         int mid = s + e >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 356 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 356 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 600 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 600 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 1 ms 600 KB Output is correct
48 Correct 146 ms 28100 KB Output is correct
49 Correct 161 ms 28236 KB Output is correct
50 Correct 169 ms 28240 KB Output is correct
51 Correct 157 ms 28316 KB Output is correct
52 Correct 156 ms 28240 KB Output is correct
53 Correct 158 ms 28240 KB Output is correct
54 Correct 157 ms 28288 KB Output is correct
55 Correct 121 ms 27980 KB Output is correct
56 Correct 132 ms 28240 KB Output is correct
57 Correct 131 ms 28240 KB Output is correct
58 Correct 130 ms 28240 KB Output is correct
59 Correct 136 ms 28244 KB Output is correct
60 Correct 129 ms 28264 KB Output is correct
61 Correct 133 ms 28224 KB Output is correct
62 Correct 2 ms 600 KB Output is correct
63 Correct 2 ms 604 KB Output is correct
64 Correct 58 ms 14672 KB Output is correct
65 Correct 62 ms 14672 KB Output is correct
66 Correct 123 ms 28240 KB Output is correct
67 Correct 127 ms 28496 KB Output is correct
68 Correct 124 ms 28240 KB Output is correct
69 Correct 72 ms 28148 KB Output is correct
70 Correct 79 ms 28192 KB Output is correct
71 Correct 73 ms 28096 KB Output is correct
72 Correct 121 ms 28496 KB Output is correct
73 Correct 77 ms 28292 KB Output is correct
74 Correct 72 ms 28316 KB Output is correct
75 Correct 2 ms 600 KB Output is correct
76 Correct 2 ms 604 KB Output is correct
77 Correct 1 ms 600 KB Output is correct
78 Correct 105 ms 28184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 600 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 1 ms 600 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 1 ms 600 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 600 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 1 ms 600 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 146 ms 28100 KB Output is correct
60 Correct 161 ms 28236 KB Output is correct
61 Correct 169 ms 28240 KB Output is correct
62 Correct 157 ms 28316 KB Output is correct
63 Correct 156 ms 28240 KB Output is correct
64 Correct 158 ms 28240 KB Output is correct
65 Correct 157 ms 28288 KB Output is correct
66 Correct 121 ms 27980 KB Output is correct
67 Correct 132 ms 28240 KB Output is correct
68 Correct 131 ms 28240 KB Output is correct
69 Correct 130 ms 28240 KB Output is correct
70 Correct 136 ms 28244 KB Output is correct
71 Correct 129 ms 28264 KB Output is correct
72 Correct 133 ms 28224 KB Output is correct
73 Correct 2 ms 600 KB Output is correct
74 Correct 2 ms 604 KB Output is correct
75 Correct 58 ms 14672 KB Output is correct
76 Correct 62 ms 14672 KB Output is correct
77 Correct 123 ms 28240 KB Output is correct
78 Correct 127 ms 28496 KB Output is correct
79 Correct 124 ms 28240 KB Output is correct
80 Correct 72 ms 28148 KB Output is correct
81 Correct 79 ms 28192 KB Output is correct
82 Correct 73 ms 28096 KB Output is correct
83 Correct 121 ms 28496 KB Output is correct
84 Correct 77 ms 28292 KB Output is correct
85 Correct 72 ms 28316 KB Output is correct
86 Correct 2 ms 600 KB Output is correct
87 Correct 2 ms 604 KB Output is correct
88 Correct 1 ms 600 KB Output is correct
89 Correct 105 ms 28184 KB Output is correct
90 Correct 205 ms 30552 KB Output is correct
91 Correct 485 ms 53588 KB Output is correct
92 Correct 536 ms 53280 KB Output is correct
93 Correct 497 ms 53568 KB Output is correct
94 Correct 497 ms 53608 KB Output is correct
95 Correct 487 ms 53612 KB Output is correct
96 Correct 482 ms 53592 KB Output is correct
97 Correct 164 ms 30896 KB Output is correct
98 Correct 475 ms 53340 KB Output is correct
99 Correct 479 ms 53924 KB Output is correct
100 Correct 475 ms 53840 KB Output is correct
101 Correct 492 ms 53332 KB Output is correct
102 Correct 536 ms 53356 KB Output is correct
103 Correct 482 ms 53584 KB Output is correct
104 Correct 400 ms 39504 KB Output is correct
105 Correct 427 ms 41548 KB Output is correct
106 Correct 525 ms 57936 KB Output is correct
107 Correct 516 ms 57916 KB Output is correct
108 Correct 562 ms 58064 KB Output is correct
109 Correct 517 ms 57808 KB Output is correct
110 Correct 533 ms 58212 KB Output is correct
111 Correct 346 ms 53824 KB Output is correct
112 Correct 354 ms 53824 KB Output is correct
113 Correct 569 ms 54864 KB Output is correct
114 Correct 873 ms 55916 KB Output is correct
115 Correct 534 ms 54864 KB Output is correct
116 Correct 384 ms 55036 KB Output is correct
117 Correct 184 ms 28240 KB Output is correct
118 Correct 182 ms 28248 KB Output is correct
119 Correct 177 ms 27216 KB Output is correct
120 Correct 206 ms 28248 KB Output is correct
121 Correct 193 ms 29272 KB Output is correct
122 Correct 625 ms 50928 KB Output is correct
123 Correct 967 ms 56148 KB Output is correct
124 Correct 968 ms 55916 KB Output is correct
125 Correct 916 ms 55768 KB Output is correct