Submission #841456

# Submission time Handle Problem Language Result Execution time Memory
841456 2023-09-01T15:40:43 Z model_code Overtaking (IOI23_overtaking) C++17
100 / 100
1278 ms 99268 KB
// correct/GA_full.cpp

#include "overtaking.h"
#include <algorithm>
#include <map>
#include <limits>

using namespace std;
using ll = long long;

const ll END = numeric_limits<ll>::max();

map<ll, ll> intervals;

void add_interval(ll start, ll end)
{
    auto it = intervals.lower_bound(end);
    if (it == intervals.begin())
    {
        intervals[start] = end;
        if (!intervals.count(end))
        {
            intervals[end] = END;
        }
        return;
    }
    --it;
    if (it->second != END && it->first <= start)
    {
        return;
    }
    ll dest = it->second == END ? end : it->second;
    if (it->second == END && !intervals.count(end))
    {
        intervals[end] = END;
    }
    intervals[start] = dest;
    while (it->first > start)
    {
        intervals.erase(it--);
    }
}

ll total_time;

void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S)
{
    total_time = L * (ll)X;
    vector<pair<ll, int>> initial;
    for (int i = 0; i < N; i++)
    {
        if (W[i] > X)
        {
            initial.emplace_back(T[i], W[i] - X);
        }
    }
    N = initial.size();
    sort(initial.begin(), initial.end());
    vector<vector<ll>> bus_time(M, vector<ll>(N));
    vector<int> bus_rv(N);
    for (int j = 0; j < N; j++)
    {
        bus_time[0][j] = initial[j].first;
        bus_rv[j] = initial[j].second;
    }
    for (int i = 1; i < M; i++)
    {
        ll dist = S[i] - S[i - 1];
        ll m = 0;
        for (int j = 0; j < N; j++)
        {
            int rv = bus_rv[j];
            ll t = bus_time[i - 1][j] + rv * dist;
            if (t <= m)
            {
                bus_time[i][j] = m;
                int k = j;
                while (k >= 1 && bus_time[i][k - 1] == m && bus_rv[k - 1] > rv)
                {
                    bus_rv[k] = bus_rv[k - 1];
                    k--;
                }
                bus_rv[k] = rv;
            }
            else
            {
                bus_time[i][j] = t;
                m = t;
            }
        }
    }
    for (int i = M - 1; i >= 1; i--)
    {
        for (int j = 0; j < N; j++)
        {
            add_interval(bus_time[i - 1][j], bus_time[i][j]);
        }
    }
}

long long arrival_time(long long Y)
{
    auto it = intervals.lower_bound(Y);
    if (it == intervals.begin())
        return Y + total_time;
    --it;
    if (it->second == END)
        return Y + total_time;
    return it->second + total_time;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 400 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 300 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 420 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 288 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 4 ms 980 KB Output is correct
33 Correct 3 ms 980 KB Output is correct
34 Correct 4 ms 980 KB Output is correct
35 Correct 4 ms 980 KB Output is correct
36 Correct 3 ms 980 KB Output is correct
37 Correct 3 ms 980 KB Output is correct
38 Correct 1 ms 284 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 400 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 288 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 4 ms 980 KB Output is correct
40 Correct 3 ms 980 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 3 ms 980 KB Output is correct
44 Correct 3 ms 980 KB Output is correct
45 Correct 1 ms 284 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 96 ms 8560 KB Output is correct
49 Correct 136 ms 9152 KB Output is correct
50 Correct 156 ms 9256 KB Output is correct
51 Correct 132 ms 9208 KB Output is correct
52 Correct 125 ms 9072 KB Output is correct
53 Correct 127 ms 9140 KB Output is correct
54 Correct 133 ms 9256 KB Output is correct
55 Correct 58 ms 8276 KB Output is correct
56 Correct 106 ms 8632 KB Output is correct
57 Correct 104 ms 8724 KB Output is correct
58 Correct 117 ms 8676 KB Output is correct
59 Correct 108 ms 8716 KB Output is correct
60 Correct 105 ms 8624 KB Output is correct
61 Correct 105 ms 8656 KB Output is correct
62 Correct 3 ms 596 KB Output is correct
63 Correct 2 ms 596 KB Output is correct
64 Correct 50 ms 4444 KB Output is correct
65 Correct 43 ms 4436 KB Output is correct
66 Correct 65 ms 8416 KB Output is correct
67 Correct 93 ms 8440 KB Output is correct
68 Correct 90 ms 8436 KB Output is correct
69 Correct 422 ms 70840 KB Output is correct
70 Correct 431 ms 70872 KB Output is correct
71 Correct 490 ms 70928 KB Output is correct
72 Correct 473 ms 52576 KB Output is correct
73 Correct 428 ms 70892 KB Output is correct
74 Correct 462 ms 70860 KB Output is correct
75 Correct 3 ms 468 KB Output is correct
76 Correct 3 ms 468 KB Output is correct
77 Correct 2 ms 468 KB Output is correct
78 Correct 186 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 400 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 308 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 300 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 4 ms 724 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 420 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 1 ms 288 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 4 ms 980 KB Output is correct
51 Correct 3 ms 980 KB Output is correct
52 Correct 4 ms 980 KB Output is correct
53 Correct 4 ms 980 KB Output is correct
54 Correct 3 ms 980 KB Output is correct
55 Correct 3 ms 980 KB Output is correct
56 Correct 1 ms 284 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 96 ms 8560 KB Output is correct
60 Correct 136 ms 9152 KB Output is correct
61 Correct 156 ms 9256 KB Output is correct
62 Correct 132 ms 9208 KB Output is correct
63 Correct 125 ms 9072 KB Output is correct
64 Correct 127 ms 9140 KB Output is correct
65 Correct 133 ms 9256 KB Output is correct
66 Correct 58 ms 8276 KB Output is correct
67 Correct 106 ms 8632 KB Output is correct
68 Correct 104 ms 8724 KB Output is correct
69 Correct 117 ms 8676 KB Output is correct
70 Correct 108 ms 8716 KB Output is correct
71 Correct 105 ms 8624 KB Output is correct
72 Correct 105 ms 8656 KB Output is correct
73 Correct 3 ms 596 KB Output is correct
74 Correct 2 ms 596 KB Output is correct
75 Correct 50 ms 4444 KB Output is correct
76 Correct 43 ms 4436 KB Output is correct
77 Correct 65 ms 8416 KB Output is correct
78 Correct 93 ms 8440 KB Output is correct
79 Correct 90 ms 8436 KB Output is correct
80 Correct 422 ms 70840 KB Output is correct
81 Correct 431 ms 70872 KB Output is correct
82 Correct 490 ms 70928 KB Output is correct
83 Correct 473 ms 52576 KB Output is correct
84 Correct 428 ms 70892 KB Output is correct
85 Correct 462 ms 70860 KB Output is correct
86 Correct 3 ms 468 KB Output is correct
87 Correct 3 ms 468 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 186 ms 23936 KB Output is correct
90 Correct 112 ms 10780 KB Output is correct
91 Correct 430 ms 34352 KB Output is correct
92 Correct 416 ms 33780 KB Output is correct
93 Correct 389 ms 34600 KB Output is correct
94 Correct 397 ms 34664 KB Output is correct
95 Correct 369 ms 33920 KB Output is correct
96 Correct 374 ms 34864 KB Output is correct
97 Correct 66 ms 10700 KB Output is correct
98 Correct 333 ms 33696 KB Output is correct
99 Correct 338 ms 32372 KB Output is correct
100 Correct 360 ms 35828 KB Output is correct
101 Correct 341 ms 35508 KB Output is correct
102 Correct 336 ms 35496 KB Output is correct
103 Correct 334 ms 30832 KB Output is correct
104 Correct 253 ms 36508 KB Output is correct
105 Correct 294 ms 34180 KB Output is correct
106 Correct 388 ms 43476 KB Output is correct
107 Correct 376 ms 43084 KB Output is correct
108 Correct 349 ms 40396 KB Output is correct
109 Correct 348 ms 41424 KB Output is correct
110 Correct 355 ms 42020 KB Output is correct
111 Correct 929 ms 97960 KB Output is correct
112 Correct 884 ms 96688 KB Output is correct
113 Correct 1170 ms 97480 KB Output is correct
114 Correct 1118 ms 70388 KB Output is correct
115 Correct 1180 ms 97348 KB Output is correct
116 Correct 1043 ms 99268 KB Output is correct
117 Correct 213 ms 38028 KB Output is correct
118 Correct 195 ms 39256 KB Output is correct
119 Correct 197 ms 37220 KB Output is correct
120 Correct 189 ms 36668 KB Output is correct
121 Correct 252 ms 37520 KB Output is correct
122 Correct 509 ms 42584 KB Output is correct
123 Correct 1278 ms 67632 KB Output is correct
124 Correct 1166 ms 60144 KB Output is correct
125 Correct 994 ms 53944 KB Output is correct