# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
845652 | ogkostya | Overtaking (IOI23_overtaking) | C++17 | 480 ms | 46960 KiB |
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;
};
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;
}
};
struct sort2
{
inline bool operator() (Point const& a, Point const& b)
{
if (a.t == b.t)
return b.w < a.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);
}
if (TW.size() == 0)
return;
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;
arr[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--)
{
ans[0][j] = arr[0][j] + 1LL * (_S[M - 1] - _S[j]) * X;
for (int i = 1; i < TW.size(); i++)
{
if (arr[i][j] == arr[i - 1][j])
{
ans[i][j] = ans[i - 1][j];
}
else
{
int ii = i - 1;
int l = j;
int r = arr[ii].size();
while (l < r)
{
int m = (l + r) / 2;
long long c = arr[i][j] + 1LL * (_S[m] - _S[j]) * X;
if (arr[ii][m] < c)
{
l = m + 1;
}
else
{
r = m;
}
}
if (l < arr[ii].size())
{
ans[i][j] = ans[ii][l];
}
else
{
ans[i][j] = arr[i][j] + 1LL * (_S[M-1] - _S[j]) * X;
}
}
}
}
}
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;
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;
return ans[i][l];
}
Compilation message (stderr)
# | 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... |