Submission #282630

#TimeUsernameProblemLanguageResultExecution timeMemory
282630DystoriaXLong Distance Coach (JOI17_coach)C++14
71 / 100
2061 ms14292 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; long long x, t; int n, m, w; long long s[200010]; pair<long long, int> v[200010]; long long pos[200010], spos[200010]; long long dp[200010], ans; long long Get(long long x){ return x - (x % t); } int main(){ scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t); for(int i = 1; i <= n; i++) scanf("%lld", &s[i]); for(int i = 1; i <= m; i++) scanf("%lld%d", &v[i].fi, &v[i].se), pos[i] = v[i].fi; sort(v + 1, v + 1 + m); sort(pos + 1, pos + 1 + m); memset(spos, -1, sizeof(spos)); s[n + 1] = x; for(int i = 1; i <= n + 1; i++){ int id = upper_bound(pos + 1, pos + 1 + m, s[i] % t) - pos; --id; if(spos[id] == -1 || spos[id] > s[i]) spos[id] = s[i]; } for(int i = 0; i <= m; i++) ans += (x - v[i].fi) / t + 1; ans *= w; for(int i = 1; i <= m; i++){ dp[i] = dp[i - 1]; if(spos[i] == -1) continue; long long cost = 0; for(int k = i - 1; k >= 0; k--){ cost += -((x - (Get(spos[i]) + v[k + 1].fi)) / t + 1) * w + v[k + 1].se; dp[i] = min(dp[i], dp[k] + cost); } } printf("%lld\n", ans + dp[m]); return 0; }

Compilation message (stderr)

coach.cpp: In function 'int main()':
coach.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%lld%d%d%d%lld", &x, &n, &m, &w, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:23:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     for(int i = 1; i <= n; i++) scanf("%lld", &s[i]);
      |                                 ~~~~~^~~~~~~~~~~~~~~
coach.cpp:25:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     for(int i = 1; i <= m; i++) scanf("%lld%d", &v[i].fi, &v[i].se), pos[i] = v[i].fi;
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...