제출 #939555

#제출 시각아이디문제언어결과실행 시간메모리
939555AdamGS추월 (IOI23_overtaking)C++17
19 / 100
3 ms15452 KiB
#include "overtaking.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e3+7;
ll dp[LIM][LIM], czas[LIM][LIM], S[LIM], n, m, X;
void init(int L, int N, vector<ll>T, vector<int>W, int _X, int M, vector<int>_S) {
  m=M; X=_X;
  rep(i, m) S[i]=_S[i];
  vector<pair<ll,ll>>P;
  rep(i, N) if(W[i]>X) P.pb({T[i], W[i]});
  n=P.size();
  if(n==0) return;
  sort(all(P));
  rep(i, n) czas[0][i]=P[i].st;
  rep(i, m-1) {
    rep(j, n) P[j].st+=(ll)(S[i+1]-S[i])*P[j].nd;
    rep(j, n-1) P[j+1].st=max(P[j+1].st, P[j].st);
    sort(all(P));
    rep(j, n) czas[i+1][j]=P[j].st;
  }
  rep(i, n) dp[m-1][i]=czas[m-1][i];
  for(int i=m-2; i>=0; --i) {
    rep(j, n) {
      int po=0, ko=j-1;
      while(po<ko) {
        int sr=(po+ko+1)/2;
        if(czas[i][sr]<czas[i][j]) po=sr; else ko=sr-1;
      }
      if(po>ko || czas[i][po]>=czas[i][j]) {
        dp[i][j]=czas[i][j]+(S[m-1]-S[i])*X;
        continue;
      }
      int xd=po;
      po=i+1; ko=m;
      while(po<ko) {
        int sr=(po+ko)/2;
        if(czas[po][xd]>=czas[i][j]+(S[po]-S[i])*X) ko=sr; else po=sr+1;
      }
      if(po==m) dp[i][j]=czas[i][j]+(S[m-1]-S[i])*X;
      else dp[i][j]=dp[po][xd];
    }
  }
}
ll arrival_time(ll Y) {
  if(n==0) return Y+(S[m-1]-S[0])*X;
  int po=0, ko=n-1;
  while(po<ko) {
    int sr=(po+ko)/2;
    if(czas[0][sr]>=Y) ko=sr; else po=sr+1;
  }
  int a=po;
  if(czas[0][a]>=Y) --a;
  if(a==-1) return Y+(S[m-1]-S[0])*X;
  po=1; ko=m;
  while(po<ko) {
    int sr=(po+ko)/2;
    if(czas[sr][a]>=Y+(S[sr]-S[0])*X) ko=sr; else po=sr+1;
  }
  if(po==m) return Y+(S[m-1]-S[0])*X;
  return dp[po][a];
}
#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...