# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
986342 |
2024-05-20T10:54:49 Z |
VMaksimoski008 |
Toll (BOI17_toll) |
C++17 |
|
414 ms |
524288 KB |
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
int32_t main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int K, n, m, q;
cin >> K >> n >> m >> q;
auto node = [&](int i, int j) { return K * i + j; };
auto id = [&](int x) { return pii{ x / K, x % K }; };
ll dp[n/K+1][K+1][n/K+1][K+1];
for(int i=0; i<=n/K; i++)
for(int j=0; j<=K; j++)
for(int k=0; k<=n/K; k++)
for(int l=0; l<=K; l++) dp[i][j][k][l] = 1e9;
for(int i=0; i<=n/K; i++)
for(int j=0; j<=K; j++) dp[i][j][i][j] = 0;
for(int i=0; i<m; i++) {
int a, b, t;
cin >> a >> b >> t;
dp[a/K][a%K][b/K][b%K] = min(dp[a/K][a%K][b/K][b%K], (ll)t);
}
//compute dp in increasing dist
for(int d=2; d<=n/K; d++) {
for(int i=0; i+d<=n/K; i++) {
for(int j=0; j<K; j++) {
for(int k=0; k<K; k++) {
if(node(i+d, k) > n) break;
for(int a=i+1; a<i+d; a++) {
for(int b=0; b<K; b++) {
dp[i][j][i+d][k] = min(dp[i][j][i+d][k], dp[i][j][a][b] + dp[a][b][i+d][k]);
}
}
}
}
}
}
while(q--) {
int a, b;
cin >> a >> b;
cout << (dp[a/K][a%K][b/K][b%K] == 1e9 ? -1 : dp[a/K][a%K][b/K][b%K]) << '\n';
}
return 0;
}
Compilation message
toll.cpp: In function 'int32_t main()':
toll.cpp:29:10: warning: variable 'id' set but not used [-Wunused-but-set-variable]
29 | auto id = [&](int x) { return pii{ x / K, x % K }; };
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
365 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
321 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
414 ms |
31840 KB |
Output is correct |
7 |
Correct |
344 ms |
18140 KB |
Output is correct |
8 |
Correct |
288 ms |
11868 KB |
Output is correct |
9 |
Correct |
303 ms |
12636 KB |
Output is correct |
10 |
Runtime error |
254 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
414 ms |
31840 KB |
Output is correct |
7 |
Correct |
344 ms |
18140 KB |
Output is correct |
8 |
Correct |
288 ms |
11868 KB |
Output is correct |
9 |
Correct |
303 ms |
12636 KB |
Output is correct |
10 |
Runtime error |
254 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
365 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |