Submission #841880

#TimeUsernameProblemLanguageResultExecution timeMemory
841880hcngOvertaking (IOI23_overtaking)C++17
65 / 100
3537 ms33440 KiB
#include <bits/stdc++.h>
#include "overtaking.h"
using namespace std;
 
#define long long long
 
long l, n, x, m;
vector<long> w, s;
vector<vector<long>> t, e, v, pre;
 
void init(int L, int N, vector<long> T, vector<int> W, int X, int M, vector<int> S) {
    
    l = L, x = X, m = M, n = N;
    s.assign(S.begin(), S.end());
    w.assign(W.begin(), W.end());
    t.resize(m); t[0].assign(T.begin(), T.end());
    w.push_back(X); t[0].push_back(0);
    e.assign(m, vector<long>(n + 1));
    v.assign(m, vector<long>(n));
    pre.assign(m, vector<long>(n));
    
    for (long i = 1; i < m; i++) {
        t[i] = vector<long>(n + 1);
        for (long j = 0; j < n; j++) {
            v[i][j] = j;
            e[i][j] = t[i - 1][j] + w[j] * (s[i] - s[i - 1]);
        }
        sort(v[i].begin(), v[i].end(),
             [&](const long &a, const long &b) {
                 return t[i - 1][a] < t[i - 1][b];
             }
        );
        pre[i][0] = e[i][v[i][0]];
        for (long j = 1; j < n; j++) {
            pre[i][j] = max(e[i][v[i][j]], pre[i][j - 1]);
        }
        for (long j = 0; j < n; j++) {
            long L = 0, R = j - 1;
            while (L < R) {
                M = (L + R + 1) / 2;
                if (t[i - 1][v[i][M]] < t[i - 1][v[i][j]]) L = M;
                else R = M - 1;
            }
            if (t[i - 1][v[i][j]] == t[i - 1][v[i][0]]) t[i][v[i][j]] = e[i][v[i][j]];
            else t[i][v[i][j]] = max(e[i][v[i][j]], pre[i][L]);
        }
    }
}
 
long arrival_time(long y) {
    
    t[0][n] = y;
    
    for (long i = 1; i < m; i++) {
        e[i][n] = t[i - 1][n] + w[n] * (s[i] - s[i - 1]);
        long L = 0, R = n - 1;
        while (L < R) {
            long M = (L + R + 1) / 2;
            if (t[i - 1][v[i][M]] < t[i - 1][n]) L = M;
            else R = M - 1;
        }
        if (t[i - 1][n] <= t[i - 1][v[i][0]]) t[i][n] = e[i][n];
        else t[i][n] = max(e[i][n], pre[i][L]);
    }
    
    return t[m - 1][n];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...