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 <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;
s.assign(S.begin(), S.end());
t.resize(m);
for (long i = 0; i < N; i++) {
if (W[i] > X) {
w.push_back(W[i]);
t[0].push_back(T[i]);
}
}
n = w.size();
w.push_back(X); t[0].push_back(0);
assert(t[0].size() == n + 1);
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]);
}
// for (long i = 1; i < m; i++) {
// vector<long> v(n + 1);
// for (long j = 0; j <= n; j++) {
// v[j] = j;
// e[i][j] = t[i - 1][j] + w[j] * (s[i] - s[i - 1]);
// }
// sort(v.begin(), v.end(),
// [&](const long &a, const long &b) {
// return t[i - 1][a] < t[i - 1][b];
// }
// );
// vector<long> pre(n + 1); pre[0] = e[i][v[0]];
// for (long j = 1; j <= n; j++) {
// pre[j] = max(e[i][v[j]], pre[j - 1]);
// }
// for (long j = 0; j <= n; j++) {
// long L = 0, R = j - 1;
// while (L < R) {
// long M = (L + R + 1) / 2;
// if (t[i - 1][v[M]] < t[i - 1][v[j]]) L = M;
// else R = M - 1;
// }
// if (t[i - 1][v[j]] == t[i - 1][v[0]]) t[i][v[j]] = e[i][v[j]];
// else t[i][v[j]] = max(e[i][v[j]], pre[L]);
// }
// }
//
// for (long i = 0; i <= n; i++) {
// for (long j = 0; j < m; j++) {
// cerr << e[j][i] << ' ' << t[j][i] << " ";
// }
// cerr << endl;
// }
return t[m - 1][n];
}
Compilation message (stderr)
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from overtaking.cpp:1:
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:25:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
25 | assert(t[0].size() == n + 1);
| ~~~~~~~~~~~~^~~~~~~~
# | 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... |