# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1053559 |
2024-08-11T13:14:12 Z |
ArthuroWich |
Toll (BOI17_toll) |
C++17 |
|
212 ms |
129876 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
vector<vector<int>> calc(vector<vector<int>> a, vector<vector<int>> b, int k) {
vector<vector<int>> ans(k, vector<int>(k, INT_MAX));
for (int x = 0; x < k; x++) {
for (int i = 0; i < k; i++) {
for (int j = 0; j < k; j++) {
ans[i][j] = min(ans[i][j], a[i][x]+b[x][j]);
}
}
}
return ans;
}
void solve() { // I dont really like this problem
int n, o, m, k;
cin >> k >> n >> m >> o;
vector<vector<vector<vector<int>>>> dp(n+1, vector<vector<vector<int>>>(17, vector<vector<int>>(k, vector<int>(k, INT_MAX))));
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
dp[u/k][0][u%k][v%k] = min(dp[u/k][0][u%k][v%k], w);
}
for (int j = 1; j < 17; j++) {
for (int i = 0; i < (n+k-1)/k; i++) {
if (i+(1<<j) >= (n+k-1)/k) {
break;
}
dp[i][j] = calc(dp[i][j-1], dp[i+(1<<j)-1][j-1], k);
}
}
while(o--) {
int a, b;
cin >> a >> b;
vector<vector<int>> ans(k, vector<int>(k, INT_MAX));
for (int i = 0; i < k; i++) {
for (int j = 0; j < k; j++) {
ans[i][i] = 0;
}
}
int i = a/k;
for (int j = 16; j >= 0; j--) {
if (i+(1<<j) <= b/k) {
ans = calc(ans, dp[i][j], k);
i += (1 << j);
}
}
if (ans[a%k][b%k] == INT_MAX) {
cout << -1 << endl;
} else {
cout << ans[a%k][b%k] << endl;
}
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
76216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
212 ms |
129876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
76216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |