# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550366 | LucaDantas | Long Distance Coach (JOI17_coach) | C++17 | 46 ms | 596 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>
using namespace std;
constexpr int maxn = 2010;
int nxt[maxn]; // next living guy after a water refill
long long X, N, M, W, T;
long long refill[maxn], time_person[maxn], kill_person[maxn], dp[maxn];
int main() {
scanf("%lld %lld %lld %lld %lld", &X, &N, &M, &W, &T);
for(int i = 1; i <= N; i++)
scanf("%lld", &refill[i]);
refill[++N] = X;
for(int i = 1; i <= M; i++)
scanf("%lld %lld", &time_person[i], &kill_person[i]);
vector<pair<long long, long long>> tempos; // o tempo T é o fim
for(int i = 1; i <= M; i++)
tempos.push_back({time_person[i], kill_person[i]});
sort(tempos.begin(), tempos.end());
for(int i = 0; i < M; i++)
time_person[i+1] = tempos[i].first, kill_person[i+1] = tempos[i].second;
time_person[M+1] = T; // setto o valor do piloto
for(int i = 1; i <= N; i++)
nxt[i] = lower_bound(time_person+1, time_person+1+M, refill[i] % T) - time_person; // ID do proximo cara vivo dps de mim
for(int i = 2; i <= M; i++)
kill_person[i] += kill_person[i-1];
auto qtd = [&](long long tempo) { return X / T + (tempo < X%T); };
auto itv_kill = [&](int l, int r) { return kill_person[r] - kill_person[l-1]; };
auto cost = [&](int l, int r, long long tempo) { return itv_kill(l, r) + (tempo / T) * W * (r-l+1); };
dp[M+1] = W * (X/T + 1);
for(int i = M; i >= 1; i--) {
long long aq = 0x3f3f3f3f3f3f3f3f;
// opção 1: uso alguem pra me matar
for(int j = 1; j <= N; j++) {
if(refill[j] % T < time_person[i]) continue;
aq = min(aq, dp[nxt[j]] + cost(i, nxt[j]-1, refill[j]));
}
// opção 2: fico vivo até o final
aq = min(aq, dp[i+1] + W * qtd(time_person[i]));
dp[i] = aq;
}
printf("%lld\n", dp[1]);
}
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... |