# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
836268 | nonono | Toll (BOI17_toll) | C++14 | 64 ms | 99068 KiB |
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;
const int INF = 5e8;
const int LOG = 20;
const int mxN = 50005;
int K, N, M, O;
int up[mxN][5][5][LOG];
signed main() {
#define taskname ""
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".ans", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
cin >> K >> N >> M >> O;
for(int i = 1; i <= M; i ++) {
int a, b, t;
cin >> a >> b >> t;
if(a / K + 1 == b / K) {
up[a / K][a % K][b % K][0] = t;
//cout << a / K << " " << a % K << " " << b % K << " " << t << "\n";
}
}
for(int k = 1; (1 << k) <= (N - 1) / K; k ++) {
for(int i = 0; i + (1 << k) <= (N - 1) / K; i ++) {
for(int j1 = 0; j1 < K; j1 ++) {
for(int j2 = 0; j2 < K; j2 ++) {
for(int j3 = 0; j3 < K; j3 ++) {
if(!up[i + (1 << k - 1)][j2][j3][k - 1]) continue ;
up[i][j1][j3][k] = up[i][j1][j2][k - 1] + up[i + (1 << k - 1)][j2][j3][k - 1];
/*cout << k << " " << i << " " << j1 << " " << j2 << " " << j3 << " " << up[i][j1][j2][k - 1] << " " <<
up[i + (1 << k - 1)][j2][j3][k - 1] << " " << up[i][j1][j3][k] << "\n";*/
}
}
}
}
}
while(O --) {
int a, b;
cin >> a >> b;
int typeA = a % K;
int typeB = b % K;
a /= K;
b /= K;
vector<int> ar(K);
for(int i = 0; i < K; i ++) ar[i] = INF;
ar[typeA] = 0;
int depth = b - a;
for(int k = 0; k <= 18; k ++) {
if(depth >> k & 1) {
vector<int> _ar(K);
for(int i = 0; i < K; i ++) {
_ar[i] = ar[i];
ar[i] = INF;
}
for(int i = 0; i < K; i ++) {
for(int j = 0; j < K; j ++) {
if(!up[a][j][i][k]) continue ;
ar[i] = min(ar[i], _ar[j] + up[a][j][i][k]);
}
}
a += (1 << k);
}
}
if(ar[typeB] >= INF) cout << -1 << "\n"; else cout << ar[typeB] << "\n";
}
return 0;
}
Compilation message (stderr)
# | 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... |