이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 || true) {
w.push_back(W[i]);
t[0].push_back(T[i]);
}
}
n = w.size();
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]);
}
// 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];
}
# | 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... |