This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
struct A{
long long l,r,t,i,j,mx;
bool operator <(const A& a)const{
return l<a.l;
}
};
long long t[1005][1005];
long long dp[1005][1005];
vector<A> a;
long long x;
long long l;
void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S)
{
x=X;
l = L;
for(int i=0 ; i<N ; i++){
t[0][i] = T[i];
}
for(int i=1 ; i<M ; i++){
vector<pair<long long,int>> v;
for(int j=0 ; j<N ; j++){
v.push_back({t[i-1][j],j});
}
sort(v.begin(),v.end(),[&](auto x,auto y){
if(x.first == y.first)return W[x.second]<W[y.second];
return x.first<y.first;
});
long long mx = 0;
long long prv = -1;
for(auto x: v){
int j = x.second;
t[i][j] = max(mx,t[i-1][j] + (S[i]-S[i-1])*1ll*W[j]);
prv = x.first;
mx=max(mx,t[i][j]);
a.push_back({t[i-1][j] - X*1ll*S[i-1],t[i][j]+X*1ll*(L-S[i]),t[i][j]+1ll*X*(L-S[i]),i,j});
}
}
for(int i=0 ;i<N ;i++)
dp[M-1][i] = t[M-1][i];
for(int i=M-2 ; i>= 0 ; i--){
vector<pair<long long,int>> v;
for(int j=0 ; j<N; j++)
v.push_back({t[i][j],j});
sort(v.begin(),v.end(),[&](auto x,auto y){
if(x.first == y.first)return W[x.second]<W[y.second];
return x.first<y.first;
});
int k = -1;
long long prv = -1;
for(auto x: v){
int j = x.second;
if(k==-1 || t[i][j] + 1ll*X*(S[i+1]-S[i]) > t[i+1][k])
dp[i][j] = t[i][j] + 1ll*X*(L-S[i]);
else
dp[i][j] = dp[i+1][k];
if(k==-1 || t[i+1][j]>t[i+1][k] )k=j;
}
}
sort(a.begin(),a.end());
a[0].mx = dp[a[0].i][a[0].j];
for(int i=1 ; i<a.size() ; i++){
a[i].mx = max(a[i-1].mx,dp[a[i].i][a[i].j]);
}
return;
}
long long arrival_time(long long Y)
{
auto k = lower_bound(a.begin(),a.end(),(A){Y,0,0,0});
if(k == a.begin()){
return Y+l*x;
}
k--;
return max(Y+l*x,k->mx);
}
Compilation message (stderr)
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:37:19: warning: variable 'prv' set but not used [-Wunused-but-set-variable]
37 | long long prv = -1;
| ^~~
overtaking.cpp:63:19: warning: unused variable 'prv' [-Wunused-variable]
63 | long long prv = -1;
| ^~~
overtaking.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<A>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i=1 ; i<a.size() ; i++){
| ~^~~~~~~~~
# | 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... |