Submission #531469

#TimeUsernameProblemLanguageResultExecution timeMemory
531469mat50013Toll (BOI17_toll)C++11
39 / 100
3056 ms6724 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int NMAX(50005); vector<pair<int, int> > G[NMAX]; ll dp[6], newDp[5]; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int k, n, m, o; cin >> k >> n >> m >> o; for(int i = 1; i <= m; ++i){ int a, b, t; cin >> a >> b >> t; G[b].push_back({a, t}); } for(int i = 1; i <= o; ++i){ int a, b; cin >> a >> b; int wh = b / k; for(int j = 0; j < k; ++j) dp[j] = LLONG_MAX / 2; dp[b % k] = 0; int fin = a / k; for(int segm = wh; segm > fin; --segm){ for(int j = 0; j < k; ++j) newDp[j] = LLONG_MAX / 2; for(int j = 0; j < k; ++j) { int nod = segm * k + j; for(auto it: G[nod]) newDp[it.first % k] = min(newDp[it.first % k], dp[j] + it.second); } for(int j = 0; j < k; ++j) dp[j] = newDp[j]; } cout << (dp[a % k] == LLONG_MAX / 2 ? - 1 : dp[a % k]) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...