이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
struct A {
ll t, s;
int idx;
bool operator < (const A& o) const {
return t < o.t;
}
} a[N][N];
ll pref[N][N], s[N];
vector<pair<ll, ll>> event;
int n, m;
ll X;
ll cal_arrival_time(ll Y) {
ll now = Y;
for (int i = 0;i < m - 1;i++) {
ll mx = now + X * (s[i + 1] - s[i]);
{
int l = -1, r = n - 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (a[i][mid].t < now) l = mid;
else r = mid - 1;
}
if (l != -1) mx = max(mx, pref[i][l]);
}
now = mx;
}
return now;
}
void init(int L, int NN, vector<ll> T, vector<int> W, int X, int M, vector<int> S) {
n = NN;
m = M;
::X = X;
for (int i = 0;i < m;i++) {
s[i] = S[i];
}
for (int i = 0;i < n;i++) {
a[0][i] = { T[i], W[i], i };
}
for (int K = 0;K < m - 1;K++) {
sort(a[K], a[K] + n);
int idx = 0;
ll mx = 0;
for (int i = 0, j;i < n;i = j) {
for (j = i;j < n && a[K][i].t == a[K][j].t;j++) {
a[K + 1][idx++] = { max(a[K][j].t + a[K][j].s * (s[K + 1] - s[K]), mx)
, a[K][j].s, a[K][j].idx };
}
for (j = i;j < n && a[K][i].t == a[K][j].t;j++) {
mx = max(mx, a[K][j].t + a[K][j].s * (s[K + 1] - s[K]));
}
for (j = i;j < n && a[K][i].t == a[K][j].t;j++) {
pref[K][j] = mx;
}
}
}
sort(a[m - 1], a[m - 1] + n);
ll INF = a[m - 1][n - 1].t;
ll cur = cal_arrival_time(0);
event.push_back({ 0, cur });
ll now = 0;
while (now <= INF) {
ll l = now + 1, r = INF + 1;
while (l < r) {
ll mid = (l + r) / 2;
if (cal_arrival_time(mid) - mid != cur - now) r = mid;
else l = mid + 1;
}
now = l;
cur = cal_arrival_time(now);
event.push_back({ now, cur });
}
}
ll arrival_time(ll Y) {
int idx = lower_bound(event.begin(), event.end(), pair<ll, ll>(Y + 1, 0ll)) - event.begin() - 1;
return event[idx].second + (Y - event[idx].first);
}
# | 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... |