이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "overtaking.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m;
int order[N];
long long t[N], w[N], s[N], f[N][N];
void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S) {
n = N; m = M;
for(int i = 0; i < n; i++) w[i] = W[i], t[i] = T[i];
for(int i = 0; i < m; i++) s[i] = S[i];
w[n] = X;
for(int i = 0; i < n; i++) order[i] = i;
for(int i = 0; i < n; i++) f[i][0] = t[i];
for(int j = 1; j < m; j++) {
sort(order, order + n, [&] (const int &x, const int &y) {
if (f[x][j - 1] != f[y][j - 1]) return f[x][j - 1] < f[y][j - 1];
return w[x] < w[y];
});
long long slowest = 0;
for(int cur = 0; cur < n; cur++) {
int i = order[cur];
f[i][j] = max(slowest, f[i][j - 1] + w[i] * (s[j] - s[j - 1]));
slowest = f[i][j];
}
}
}
long long arrival_time(long long Y) {
long long pre = Y;
for(int j = 1; j < m; j++) {
long long nxt = pre + w[n] * (s[j] - s[j - 1]);
for(int i = 0; i < n; i++) if (f[i][j - 1] < pre && w[i] > w[n]) {
nxt = max(nxt, f[i][j]);
}
pre = nxt;
// cout << pre << " ";
}
return pre;
}
#ifdef ngu
int main()
{
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int L, N, X, M, Q;
assert(5 == scanf("%d %d %d %d %d", &L, &N, &X, &M, &Q));
std::vector<long long> T(N);
for (int i = 0; i < N; i++)
assert(1 == scanf("%lld", &T[i]));
std::vector<int> W(N);
for (int i = 0; i < N; i++)
assert(1 == scanf("%d", &W[i]));
std::vector<int> S(M);
for (int i = 0; i < M; i++)
assert(1 == scanf("%d", &S[i]));
std::vector<long long> Y(Q);
for (int i = 0; i < Q; i++)
assert(1 == scanf("%lld", &Y[i]));
fclose(stdin);
init(L, N, T, W, X, M, S);
std::vector<long long> res(Q);
for (int i = 0; i < Q; i++)
res[i] = arrival_time(Y[i]);
for (int i = 0; i < Q; i++)
printf("%lld\n", res[i]);
fclose(stdout);
return 0;
}
#endif // ngu
# | 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... |