# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1049010 | Zicrus | Overtaking (IOI23_overtaking) | C++17 | 3554 ms | 41680 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 <bits/stdc++.h>
#include "overtaking.h"
using namespace std;
typedef long long ll;
vector<vector<ll>> tCur, tNxt;
vector<ll> s;
ll x, m;
void init(int l1, int n1, vector<ll> t, vector<int> w, int x1, int m1, vector<int> s1) {
ll l = l1;
ll n = n1;
s = vector<ll>(s1.size());
for (ll i = 0; i < s1.size(); i++) s[i] = s1[i];
m = m1;
x = x1;
tCur = vector<vector<ll>>(m-1);
tNxt = vector<vector<ll>>(m-1);
vector<pair<ll, ll>> busses;
for (ll i = 0; i < n; i++) {
if (w[i] <= x) continue;
busses.push_back({t[i], w[i]});
}
sort(busses.begin(), busses.end());
n = busses.size();
for (ll t = 0; t < m-1; t++) {
for (ll i = 0; i < n; i++) {
ll curTime = busses[i].first;
if (t > 0) {
ll idealNxt = curTime + busses[i].second * (s[t] - s[t-1]);
auto iter = lower_bound(tCur[t-1].begin(), tCur[t-1].end(), curTime);
ll id = iter - tCur[t-1].begin();
ll mxNxt = id > 0 ? tNxt[t-1][id-1] : 0;
busses[i].first = curTime = max(idealNxt, mxNxt);
}
ll idealNxt = curTime + busses[i].second * (s[t+1] - s[t]);
auto iter = lower_bound(tCur[t].begin(), tCur[t].end(), curTime);
ll id = iter - tCur[t].begin();
ll mxNxt = id > 0 ? tNxt[t][id-1] : 0;
ll nxt = max(idealNxt, mxNxt);
if (nxt > mxNxt) {
if (id < tCur[t].size() && curTime == tCur[t][id]) {
if (nxt > tNxt[t][id]) tNxt[t][id] = nxt;
}
else {
auto iter2 = upper_bound(tNxt[t].begin(), tNxt[t].end(), nxt);
tCur[t].erase(iter, tCur[t].begin() + (iter2 - tNxt[t].begin()));
tNxt[t].erase(tNxt[t].begin() + id, iter2);
tCur[t].insert(iter, curTime);
tNxt[t].insert(tNxt[t].begin() + id, nxt);
}
}
}
}
}
ll arrival_time(ll y) {
for (int t = 0; t < m-1; t++) {
ll idealNxt = y + x * (s[t+1] - s[t]);
ll id = lower_bound(tCur[t].begin(), tCur[t].end(), y) - tCur[t].begin();
ll mxNxt = id > 0 ? tNxt[t][id-1] : 0;
y = max(idealNxt, mxNxt);
}
return y;
}
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... |