# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
550366 | LucaDantas | Long Distance Coach (JOI17_coach) | C++17 | 46 ms | 596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
}
컴파일 시 표준 에러 (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... |