제출 #966547

#제출 시각아이디문제언어결과실행 시간메모리
966547nguyentunglam추월 (IOI23_overtaking)C++17
39 / 100
3536 ms8284 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...