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 <algorithm>
#include <utility>
#include <list>
#include <climits>
class Point
{
public:
long long t, w;
int i;
};
std::vector<std::vector<Point>> SS(1001, std::vector<Point>());
struct sort1
{
inline bool operator() (Point const& a, Point const& b)
{
if (a.t == b.t)
return a.w < b.w;
return a.t < b.t;
}
};
int _M;
std::vector<int> _S;
int _X;
std::vector<std::vector<long long>> arr;
std::vector<std::vector<long long>> ans;
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;
_M = M;
_S = S;
std::vector<Point> TW;
TW.reserve(N);
for (int i = 0; i < N; i++)
{
if (W[i] < X)
continue;
Point p = { T[i], W[i] };
TW.push_back(p);
}
long long mb = 0;
arr = std::vector<std::vector<long long>>(TW.size(), std::vector<long long>(M));
ans = std::vector<std::vector<long long>>(TW.size(), std::vector<long long>(M));
std::sort(TW.begin(), TW.end(), sort1());
for (int i = 0; i < TW.size(); i++)
{
arr[i][0] = TW[i].t;
TW[i].i = i;
}
for (int j = 1; j < M; j++)
{
std::sort(TW.begin(), TW.end(), sort1());
mb = 0;
for (int i = 0; i < TW.size(); i++)
{
long long a = TW[i].t;
long long b = a + (_S[j] - _S[j - 1]) * TW[i].w;
if (b < mb)
b = mb;
else
mb = b;
if (SS[j].size() == 0 || SS[j].back().w != b && (i + 1 == TW.size() || TW[i].t != TW[i + 1].t))
{
SS[j].push_back({ a, b, TW[i].i });
}
arr[TW[i].i][j] = b;
TW[i].t = b;
}
}
for (int i = 0; i < TW.size(); i++)
{
ans[i][M-1] = arr[i][M - 1];
}
for (int j = M - 2; j >= 1; j--)
{
for (int i = 0; i < TW.size(); i++)
{
long long b = arr[i][j] + 1LL * (_S[j + 1] - _S[j]) * X;
ans[i][j] = b;
if (SS[j+1].size() > 0 && SS[j + 1][0].t < arr[i][j])
{
int l = 0, r = SS[j + 1].size();
while (l < r)
{
int m = (l + r + 1) / 2;
if (m == SS[j + 1].size())
{
break;
}
else if (SS[j + 1][m].t < arr[i][j])
{
l = m;
}
else
{
r = m - 1;
}
}
if (l < SS[j + 1].size() && b < SS[j + 1][l].w)
ans[i][j] = ans[SS[j + 1][l].i][j+1];
}
}
}
}
long long arrival_time(long long Y)
{
long long b = Y + 1LL * _S[_M - 1] * _X;
if (arr.size() == 0)
return b;
int i = 0, j = 0;
if (arr[0][0] >= Y)
return b;
int l = 0, r = arr.size();
while (l < r)
{
int m = (l + r + 1) / 2;
if (m == arr.size())
{
break;
}
else if (arr[m][0] < Y)
{
l = m;
}
else
{
r = m - 1;
}
}
i = l;
l = 0;
r = arr[i].size();
while (l < r)
{
int m = (l + r) / 2;
long long c = Y + 1LL * _S[m] * _X;
if (arr[i][m] < c)
{
l = m + 1;
}
else
{
r = m;
}
}
if (l == arr[i].size())
return b;
j = l;
return ans[i][j];
}
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:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:71:68: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | if (SS[j].size() == 0 || SS[j].back().w != b && (i + 1 == TW.size() || TW[i].t != TW[i + 1].t))
| ~~~~~~^~~~~~~~~~~~
overtaking.cpp:71:58: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
71 | if (SS[j].size() == 0 || SS[j].back().w != b && (i + 1 == TW.size() || TW[i].t != TW[i + 1].t))
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
overtaking.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:97:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | if (m == SS[j + 1].size())
| ~~^~~~~~~~~~~~~~~~~~~
overtaking.cpp:111:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
111 | if (l < SS[j + 1].size() && b < SS[j + 1][l].w)
| ~~^~~~~~~~~~~~~~~~~~
overtaking.cpp: In function 'long long int arrival_time(long long int)':
overtaking.cpp:133:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
133 | if (m == arr.size())
| ~~^~~~~~~~~~~~~
overtaking.cpp:162:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
162 | if (l == arr[i].size())
| ~~^~~~~~~~~~~~~~~~
# | 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... |