Submission #1088007

# Submission time Handle Problem Language Result Execution time Memory
1088007 2024-09-13T17:04:41 Z Valaki2 Overtaking (IOI23_overtaking) C++17
19 / 100
12 ms 1116 KB
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;

#define int __int128_t
//#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int inf = 2e18 + 42;

struct node {
    int pl, pr;
    int vl, vr;
    int val;
    node() {
        pl = 0, pr = 0;
        vl = 0, vr = 0;
        val = 0;
    }
    node(int vl_, int vr_) {
        pl = 0, pr = 0;
        vl = vl_, vr = vr_;
        val = 0;
    } 
};

int l, n, m;
vector<pii > buses;
int new_speed;
vector<int> nxt_dist;
vector<vector<node> > tree;
//vector<map<int, int> > tree;

/*void upd(int idx, int pos, int val, int cur = 1) {
    vector<node> &t = tree[idx];
    if(t[cur].vl != t[cur].vr) {
        int mid = (t[cur].vl + t[cur].vr) / 2;
        if(pos <= mid) {
            if(t[cur].pl == 0) {
                t[cur].pl = t.size();
                t.pb(node(t[cur].vl, mid));
            }
            upd(idx, pos, val, t[cur].pl);
        } else {
            if(t[cur].pr == 0) {
                t[cur].pr = t.size();
                t.pb(node(mid + 1, t[cur].vr));
            }
            upd(idx, pos, val, t[cur].pr);
        }
        t[cur].val = max(t[t[cur].pl].val, t[t[cur].pr].val);
    } else {
        t[cur].val = max(t[cur].val, val);
    }
}

int qry(int idx, int ql, int qr, int cur = 1) {
    vector<node> &t = tree[idx];
    if(ql > t[cur].vr || qr < t[cur].vl) {
        return 0;
    }
    if(ql == t[cur].vl && qr == t[cur].vr) {
        return t[cur].val;
    }
    int mid = (t[cur].vl + t[cur].vr) / 2;
    if(t[cur].pl == 0) {
        t[cur].pl = t.size();
        t.pb(node(t[cur].vl, mid));
    }
    if(t[cur].pr == 0) {
        t[cur].pr = t.size();
        t.pb(node(mid + 1, t[cur].vr));
    }
    return max(qry(idx, ql, min(qr, mid), t[cur].pl), qry(idx, max(ql, mid + 1), qr, t[cur].pr));
}*/

vector<map<int, int> > arr;

void upd(int idx, int pos, int val) {
    arr[idx][pos] = max(arr[idx][pos], val);
}

int qry(int idx, int junk, int pos) {
    int res = -inf;
    for(pii p : arr[idx]) {
        if(p.fi <= pos) {
            res = max(res, p.se);
        }
    }
    return res;
}

/*void upd(int idx, int pos, int val) {
    while(pos <= inf) {
        //int &cur = tree[idx][pos];
        //cur = max(cur, val);
        tree[idx][pos] = max(tree[idx][pos], val);
        //if(inf - (pos & (-pos)) <= pos) {
            //
        //}
        pos += pos & (-pos);
    }
}

int qry(int idx, int pos) {
    int res = 0;
    while(pos > 0) {
        res = max(res, tree[idx][pos]);
        pos -= pos & (-pos);
    }
    return res;
}*/

void init(signed L, signed N, vector<ll> T, vector<signed> W, signed X, signed M, vector<signed> S)
{
    l = L, n = N, new_speed = X, m = M;
    buses.resize(n);
    for(int i = 0; i < n; i++) {
        buses[i] = mp(W[i], T[i] + 1);
    }
    sort(buses.begin(), buses.end());
    nxt_dist.resize(m + 1);
    nxt_dist[0] = 0;
    for(int i = 1; i < m; i++) {
        nxt_dist[i] = S[i] - S[i - 1];
    }
    // setup done
    tree.assign(1 + m, {node(), node(1, inf)});
    arr.resize(1 + m);
    //tree.resize(1 + m);
    for(pii bus : buses) {
        int speed = bus.fi, start = bus.se;
        for(int i = 1; i < m; i++) {
            int current = start + speed * nxt_dist[i];
            int other = qry(i, 1, start);
            upd(i, start + 1, current);
            if(other >= current) {
                start = other;
            } else {
                start = current;
            }
        }
    }
}

ll arrival_time(ll Y)
{
    int speed = new_speed, start = Y + 1;
    for(int i = 1; i < m; i++) {
        int current = start + speed * nxt_dist[i];
        int other = qry(i, 1, start);
        if(other >= current) {
            start = other;
        } else {
            start = current;
        }
    }
    return start - 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 7 ms 604 KB Output is correct
9 Correct 8 ms 816 KB Output is correct
10 Correct 7 ms 600 KB Output is correct
11 Correct 7 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 9 ms 604 KB Output is correct
8 Correct 8 ms 588 KB Output is correct
9 Correct 8 ms 600 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 8 ms 604 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 5 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 12 ms 1116 KB 38th lines differ - on the 1st token, expected: '7670153', found: '7670001'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 8 ms 816 KB Output is correct
11 Correct 7 ms 600 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 12 ms 1116 KB 38th lines differ - on the 1st token, expected: '7670153', found: '7670001'
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 8 ms 816 KB Output is correct
11 Correct 7 ms 600 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 9 ms 604 KB Output is correct
20 Correct 8 ms 588 KB Output is correct
21 Correct 8 ms 600 KB Output is correct
22 Correct 8 ms 348 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 8 ms 604 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 5 ms 556 KB Output is correct
27 Incorrect 12 ms 1116 KB 38th lines differ - on the 1st token, expected: '7670153', found: '7670001'
28 Halted 0 ms 0 KB -