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 <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
vector<vector <pair<ll, int>>> dp;
vector<vector <ll>> esim;
vector <ll> t;
vector <int> w, s;
int n;
int x;
int l;
int m;
bool cmp(pair<ll, int> x, pair<ll, int> y) {
if (x.first != y.first) return x.first < y.first;
if (w[x.second] != w[y.second]) return w[x.second] < w[y.second];
return x.second < y.second;
}
void init(int L, int N, vector<ll> T, vector<int> W, int X, int M, vector<int> S) {
//dp[i][j] = [1, i] avtoneri simulyaciayi jamanak (j-rd) stanciayum hertakanutyun
m = M;
l = L;
x = X;
s = S;
dp.clear();
for (int i = 0; i < N; i++) {
if (W[i] > x) {
//cout << "? " << T[i] << " " << W[i] << "\n";
t.push_back(T[i]);
w.push_back(W[i]);
n++;
}
}
dp.resize(m);
esim.resize(m);
for (int i = 0; i < n; i++) {
dp[0].push_back({ t[i], i });
}
sort(dp[0].begin(), dp[0].end(), cmp);
for (int j = 1; j < m; j++) {
ll cur_mx = 0;
for (auto& it : dp[j - 1]) {
cur_mx = max(cur_mx, it.first + w[it.second] * 1ll * (s[j] - s[j - 1]));
dp[j].push_back({ cur_mx, it.second });
}
sort(dp[j].begin(), dp[j].end(), cmp);
map <int, ll> mp;
for (auto& it : dp[j]) {
mp[it.second] = it.first;
}
cur_mx = 0;
for (auto& it : dp[j - 1]) {
cur_mx = max(cur_mx, mp[it.second]);
esim[j].push_back(cur_mx);
}
}
}
ll arrival_time(ll Y) {
int cur_ind = 0;
for (auto it : t) {
if (it < Y) cur_ind++;
}
if (cur_ind == 0) {
return l * 1ll * x;
}
ll time = Y;
for (int i = 1; i < m; i++) {
time = max(time + (s[i] - s[i - 1]) * 1ll * x, esim[i][cur_ind - 1]);
while (cur_ind > 0 && dp[i][cur_ind - 1].first == time) {
cur_ind--;
}
if (cur_ind == 0) {
return (l - s[i]) * 1ll * x + time;
}
}
return time;
}
/*
int main() {
init(6, 4, { 20, 10, 40, 0 }, { 5, 20, 20, 30 }, 10, 4, { 0, 1, 3, 6 });
cout << arrival_time(0) << "\n";
cout << arrival_time(50) << "\n";
}
*/
# | 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... |