Submission #848245

# Submission time Handle Problem Language Result Execution time Memory
848245 2023-09-11T18:56:20 Z MuntherCarrot Overtaking (IOI23_overtaking) C++17
65 / 100
3500 ms 34520 KB
// by me
#include "overtaking.h"

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(x) x.begin(), x.end()
const int MOD = 1e9 + 7, SZ = 1e5 + 10, INF = 1e9;

// segment tree v0.2 :skull:
template<typename T> struct segTree{
    vector<T> t;
    int N;

    segTree(int n) : N(1){
        while(N < n) N *= 2;
        t.assign(N * 2, T());
    }

    segTree(vector<int> &vec) : segTree(vec.size()){
        for(int i = 0; i < vec.size(); i++){
            t[i + N] = vec[i];
        }
        for(int i = N - 1; i > 0; i--){
            t[i] = t[i * 2] + t[i * 2 + 1];
        }
    }

    void upd(int i, T val){
        i += N;
        t[i] = val;
        for(i /= 2; i; i /= 2){
            t[i] = t[i * 2] + t[i * 2 + 1];
        }
    }

    T get(int l, int r, int i, int from, int to){
        if(from > r || to < l){
            return T();
        }
        if(from >= l && to <= r){
            return t[i];
        }
        int mid = (from + to) / 2;
        return get(l, r, i * 2, from, mid) + get(l, r, i * 2 + 1, mid + 1, to);
    }

    T clc(int l, int r){
        return get(l, r, 1, 1, N);
    }
};

vector<vector<ll>> vec;
vector<int> w, s;
vector<ll> t;
int n, m, x;

void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S)
{
    n = N, m = M, w = W, s = S, t = T, x = X;
    vec.assign(M, vector<ll>(N));

    vector<pair<ll, int>> vv(n);
    for(int i = 0; i < n; i++){
        if(w[i] <= X) continue;
        vv[i] = {t[i], w[i]};
    }

    sort(all(vv));
    for(int i = 0; i < n; i++){
        vec[0][i] = vv[i].first;
    }

    for(int j = 1; j < m; j++){
        sort(all(vv));
        for(int i = 0; i < n; i++){
            vv[i].first += 1ll * vv[i].second * (s[j] - s[j - 1]);
            if(i){
                vv[i].first = max(vv[i].first, vv[i - 1].first);
            }
            vec[j][i] = vv[i].first;
        }
    }

    // for(int j = 0; j < m; j++){
    //     for(int i = 0; i < n; i++){
    //         cout << vec[j][i] << ' ';
    //     }
    //     cout << endl;
    // }
    return;
}
long long arrival_time(long long Y)
{
    ll ans = Y;
    int idx = lower_bound(all(vec[0]), ans) - vec[0].begin();

    if(idx == 0){
        return 1ll * x * s[m - 1] + Y;
    }
    for(int j = 0; j < m; j++){
        ll f = 1ll * x * (s[j] - (j ? s[j - 1] : 0));
        if(idx && vec[j][idx - 1] > ans + f){
            ans = vec[j][idx - 1];
            // dif += abs(vec[j][idx - 1] - f - dif);
            // f += vec[j][idx - 1] - ans - f;
            // ans = vec[j]
        }
        else ans += f;
        // idx = lower_bound(all(vec[j]), ans) - vec[j].begin();
        while(idx && vec[j][idx - 1] >= ans) idx--;
    }
    return ans;
}
// int32_t main(){
//     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//     int L, N, X, M, Q;
//     assert(5 == scanf("%d %d %d %d %d", &L, &N, &X, &M, &Q));
//     std::vector<long long> T(N);
//     for (int i = 0; i < N; i++)
//         assert(1 == scanf("%lld", &T[i]));
//     std::vector<int> W(N);
//     for (int i = 0; i < N; i++)
//         assert(1 == scanf("%d", &W[i]));
//     std::vector<int> S(M);
//     for (int i = 0; i < M; i++)
//         assert(1 == scanf("%d", &S[i]));
//     std::vector<long long> Y(Q);
//     for (int i = 0; i < Q; i++)
//         assert(1 == scanf("%lld", &Y[i]));
//
//     // fclose(stdin);
//
//     init(L, N, T, W, X, M, S);
//     std::vector<long long> res(Q);
//     for (int i = 0; i < Q; i++)
//         res[i] = arrival_time(Y[i]);
//
//     for (int i = 0; i < Q; i++)
//         printf("%lld\n", res[i]);
//     // fclose(stdout);
//     return 0;
// }
// by me
# Verdict Execution time Memory Grader output
1 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 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 5 ms 348 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 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 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 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 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 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 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 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 348 KB Output is correct
24 Correct 1 ms 344 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 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 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 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 5 ms 348 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 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 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 20 ms 8280 KB Output is correct
49 Correct 34 ms 8400 KB Output is correct
50 Correct 34 ms 8280 KB Output is correct
51 Correct 36 ms 8280 KB Output is correct
52 Correct 34 ms 8284 KB Output is correct
53 Correct 33 ms 8440 KB Output is correct
54 Correct 34 ms 8280 KB Output is correct
55 Correct 25 ms 8280 KB Output is correct
56 Correct 35 ms 8280 KB Output is correct
57 Correct 36 ms 8280 KB Output is correct
58 Correct 35 ms 8400 KB Output is correct
59 Correct 34 ms 8280 KB Output is correct
60 Correct 36 ms 8280 KB Output is correct
61 Correct 38 ms 8408 KB Output is correct
62 Correct 13 ms 600 KB Output is correct
63 Correct 2 ms 600 KB Output is correct
64 Correct 37 ms 4440 KB Output is correct
65 Correct 28 ms 4440 KB Output is correct
66 Correct 51 ms 8280 KB Output is correct
67 Correct 54 ms 8280 KB Output is correct
68 Correct 52 ms 8536 KB Output is correct
69 Correct 48 ms 8280 KB Output is correct
70 Correct 45 ms 8280 KB Output is correct
71 Correct 41 ms 8280 KB Output is correct
72 Correct 47 ms 8280 KB Output is correct
73 Correct 43 ms 8404 KB Output is correct
74 Correct 41 ms 8280 KB Output is correct
75 Correct 28 ms 8280 KB Output is correct
76 Correct 29 ms 8280 KB Output is correct
77 Correct 36 ms 8280 KB Output is correct
78 Correct 30 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 5 ms 348 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 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 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 20 ms 8280 KB Output is correct
60 Correct 34 ms 8400 KB Output is correct
61 Correct 34 ms 8280 KB Output is correct
62 Correct 36 ms 8280 KB Output is correct
63 Correct 34 ms 8284 KB Output is correct
64 Correct 33 ms 8440 KB Output is correct
65 Correct 34 ms 8280 KB Output is correct
66 Correct 25 ms 8280 KB Output is correct
67 Correct 35 ms 8280 KB Output is correct
68 Correct 36 ms 8280 KB Output is correct
69 Correct 35 ms 8400 KB Output is correct
70 Correct 34 ms 8280 KB Output is correct
71 Correct 36 ms 8280 KB Output is correct
72 Correct 38 ms 8408 KB Output is correct
73 Correct 13 ms 600 KB Output is correct
74 Correct 2 ms 600 KB Output is correct
75 Correct 37 ms 4440 KB Output is correct
76 Correct 28 ms 4440 KB Output is correct
77 Correct 51 ms 8280 KB Output is correct
78 Correct 54 ms 8280 KB Output is correct
79 Correct 52 ms 8536 KB Output is correct
80 Correct 48 ms 8280 KB Output is correct
81 Correct 45 ms 8280 KB Output is correct
82 Correct 41 ms 8280 KB Output is correct
83 Correct 47 ms 8280 KB Output is correct
84 Correct 43 ms 8404 KB Output is correct
85 Correct 41 ms 8280 KB Output is correct
86 Correct 28 ms 8280 KB Output is correct
87 Correct 29 ms 8280 KB Output is correct
88 Correct 36 ms 8280 KB Output is correct
89 Correct 30 ms 8284 KB Output is correct
90 Correct 754 ms 10640 KB Output is correct
91 Correct 3368 ms 34300 KB Output is correct
92 Correct 3415 ms 34260 KB Output is correct
93 Correct 3242 ms 34300 KB Output is correct
94 Correct 3430 ms 34260 KB Output is correct
95 Correct 3321 ms 34520 KB Output is correct
96 Correct 3292 ms 34256 KB Output is correct
97 Correct 751 ms 10576 KB Output is correct
98 Execution timed out 3515 ms 24396 KB Time limit exceeded
99 Halted 0 ms 0 KB -