Submission #550366

#TimeUsernameProblemLanguageResultExecution timeMemory
550366LucaDantasLong Distance Coach (JOI17_coach)C++17
71 / 100
46 ms596 KiB
#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)

coach.cpp: In function 'int main()':
coach.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%lld %lld %lld %lld %lld", &X, &N, &M, &W, &T);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%lld", &refill[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
coach.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%lld %lld", &time_person[i], &kill_person[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...