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;
#define int long long
const int mxN = 1007;
int n, len, x, m, y, t[mxN][mxN], e[mxN][mxN], gt[mxN][mxN], pref[mxN][mxN];
vector<int> s, vec;
vector<pair<int,int>> arr;
int cur_ind;
bool cmp(int a, int b) {
if (t[a][cur_ind] == t[b][cur_ind]) {
return arr[a].second < arr[b].second;
}
return t[a][cur_ind] < t[b][cur_ind];
}
void init(int32_t L, int32_t N, std::vector<long long> T, std::vector<int32_t> W, int32_t X, int32_t M, std::vector<int32_t> S)
{
n = N, len = L, m = M, x = X;
vector<int> inds;
for (int i = 0; i < n; ++i) {
arr.push_back({T[i], W[i]});
vec.push_back(T[i]);
inds.push_back(i);
}
sort(arr.begin(), arr.end());
sort(vec.begin(), vec.end());
for (int i = 0; i < n; ++i) {
t[i][0] = arr[i].first;
}
for (int i = 0; i < m; ++i) {
s.push_back(S[i]);
}
for (int j = 1; j < m; ++j) {
for (int i = 0; i < n; ++i) {
e[i][j] = t[i][j - 1] + arr[i].second * (s[j] - s[j - 1]);
}
cur_ind = j - 1;
sort(inds.begin(), inds.end(), cmp);
int mx = 0;
for (auto i : inds) {
mx = max(mx, e[i][j]);
t[i][j] = mx;
}
mx = -1;
int id = 0;
for (int i = 0; i < n; ++i) {
if (mx <= t[i][j]) {
mx = t[i][j];
id = i;
}
pref[i][j] = id;
}
}
for (int i = 0; i < n; ++i) {
gt[i][m - 1] = t[i][m - 1];
}
for (int j = m - 2; j >= 0; --j) {
cur_ind = j;
sort(inds.begin(), inds.end(), cmp);
pair<int,int> mn = {LLONG_MAX, LLONG_MAX};
int check = 0;
for (auto i : inds) {
gt[i][j] = max(check, t[i][j] + x * (len - s[j]));
int lb = j + 1, rb = m - 1, res = 0;
while (lb <= rb) {
int mb = (lb + rb) / 2;
if (t[i][mb] >= t[i][j] + x * (s[mb] - s[j])) {
rb = mb - 1;
if (mb < mn.first || (mb == mn.first && t[i][mb] >= mn.second)) {
mn = {mb, t[i][mb]};
check = gt[i][mb];
}
}
else {
lb = mb + 1;
}
}
}
}
}
long long arrival_time(long long Y)
{
y = Y;
int ind = lower_bound(vec.begin(), vec.end(), y) - vec.begin();
if (!ind) {
return y + x * len;
}
ind--;
int lb = 0, rb = m - 1, res = -1;
while (lb <= rb) {
int mb = (lb + rb) / 2;
int id = pref[ind][mb];
int vala = y + s[mb] * x, valb = t[id][mb];
if (valb >= vala) {
rb = mb - 1;
res = gt[id][mb];
}
else {
lb = mb + 1;
}
}
if (res == -1) {
return y + x * len;
}
return res;
}
Compilation message (stderr)
overtaking.cpp: In function 'void init(int32_t, int32_t, std::vector<long long int>, std::vector<int>, int32_t, int32_t, std::vector<int>)':
overtaking.cpp:79:41: warning: unused variable 'res' [-Wunused-variable]
79 | int lb = j + 1, rb = m - 1, res = 0;
| ^~~
# | 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... |