Submission #939730

#TimeUsernameProblemLanguageResultExecution timeMemory
939730AdamGSOvertaking (IOI23_overtaking)C++17
100 / 100
423 ms59240 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) { dp[i][0]=czas[i][0]+(S[m-1]-S[i])*X; for(int j=1; j<n; ++j) { int po=i+1, ko=m; while(po<ko) { int sr=(po+ko)/2; if(czas[sr][j-1]>=czas[i][j]+(S[sr]-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][j-1]; if(czas[i][j]==czas[i][j-1]) dp[i][j]=min(dp[i][j], dp[i][j-1]); } for(int j=n-2; j>=0; --j) if(czas[i][j]==czas[i][j+1]) dp[i][j]=min(dp[i][j], dp[i][j+1]); } } 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...