This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
using i32 = int;
#define int long long
#define len(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inf 1000'000'000'000'000'000LL
template<typename T>
using vec = vector<T>;
template<typename T>
using graph = vec<vec<T>>;
namespace Params {
int L, N;
vec<int> T, W;
int X, M;
vec<int> S;
}
vec<vec<int>> e;
vec<vec<pair<int, int>>> te;
void init(i32 L, i32 N, std::vector<int> T, std::vector<i32> W, i32 X, i32 M, std::vector<i32> S) {
Params::L = L;
Params::N = N;
Params::T = T;
Params::W.resize(N);
for (int i = 0; i < N; i++) {
Params::W[i] = W[i];
}
Params::X = X;
Params::M = M;
Params::S.resize(M);
for (int i = 0; i < M; i++) {
Params::S[i] = S[i];
}
e.resize(N, vec<int>(M, 0));
te.resize(M);
for (int i = 0; i < N; i++) {
e[i][0] = T[i];
}
for (int j = 1; j < M; j++) {
vec<int> ord(N);
iota(all(ord), 0);
sort(all(ord), [&](int x, int y) {
return e[x][j - 1] < e[y][j - 1];
});
int before = 0;
int cur = 0;
for (int k = 0; k < len(ord); k++) {
int i = ord[k];
if (k != 0) {
if (e[i][j - 1] != e[ord[k - 1]][j - 1]) {
before = max(before, cur);
cur = 0;
}
}
e[i][j] = max(e[i][j - 1] + (Params::S[j] - Params::S[j - 1]) * Params::W[i], before);
cur = max(cur, e[i][j]);
}
for (int i = 0; i < N; i++) {
te[j - 1].emplace_back(e[i][j - 1], e[i][j]);
}
sort(all(te[j - 1]));
for (int i = 1; i < N; i++) {
te[j - 1][i].second = max(te[j - 1][i].second, te[j - 1][i - 1].second);
}
}
}
int arrival_time(int Y) {
int cur_time = Y;
for (int j = 1; j < Params::M; j++) {
int time = 0;
// for (int i = 0; i < Params::N; i++) {
// if (e[i][j - 1] < cur_time)
// time = max(time, e[i][j]);
// }
int tl = 0;
int tr = len(te[j - 1]) - 1;
while (tl != tr) {
int tm = (tl + tr + 1) / 2;
if (te[j - 1][tm].first < cur_time) {
tl = tm;
} else {
tr = tm - 1;
}
}
if (te[j - 1][tl].first < cur_time) {
time = te[j - 1][tl].second;
}
time = max(time, cur_time + (Params::S[j] - Params::S[j - 1]) * Params::X);
cur_time = time;
}
return cur_time;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |