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;
int k, n, m, o, x, y, z, i, j, cost[50010][5], ans[50010];
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
memset(cost, 63, sizeof cost);
cin >> k >> n >> m >> o;
while(m--) {
cin >> x >> y >> z;
cost[x][y%k] = z;
}
while(o--) {
cin >> x >> y;
for(i = x; i <= y; ++i) ans[i] = 1e9; ans[x] = 0;
for(i = x; i < y/k*k; i++) for(j = 0; j < k; j++)
ans[i/k*k+k+j] = min(ans[i] + cost[i][j], ans[i/k*k+k+j]);
cout << (ans[y]==1e9?-1:ans[y]) << '\n';
}
}
Compilation message (stderr)
toll.cpp: In function 'int main()':
toll.cpp:15:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
15 | for(i = x; i <= y; ++i) ans[i] = 1e9; ans[x] = 0;
| ^~~
toll.cpp:15:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
15 | for(i = x; i <= y; ++i) ans[i] = 1e9; ans[x] = 0;
| ^~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |