이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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)
{
vector<long long> tt;
vector<int> w;
for(int i=0 ;i<N ; i++){
if(W[i]>X){
tt.push_back(T[i]);
w.push_back(W[i]);
}
}
N = tt.size();
T = tt;
W =w;
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;
});
for(int j=0 ; j<N ; j++){
dp[i][j]= t[i][j]+1ll*X*(L-S[i]);
for(int k = i ; k<=M-2 ; k++){
for(int l=0 ; l<N ; l++){
if(t[i][j]+1ll*(S[k]-S[i])*X>t[k][l] && t[i][j]+1ll*(S[k+1]-S[i])*X<t[k+1][l])
dp[i][j]=max(dp[i][j],dp[k+1][l]);
}
}
}
}
sort(a.begin(),a.end());
if(!a.empty())
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});
if(a.empty() || k == a.begin()){
return Y+l*x;
}
k--;
return max(Y+l*x,k->mx);
}
컴파일 시 표준 에러 (stderr) 메시지
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:48:19: warning: variable 'prv' set but not used [-Wunused-but-set-variable]
48 | long long prv = -1;
| ^~~
overtaking.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<A>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | 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... |