# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134255 | Kastanda | Toll (BOI17_toll) | C++11 | 169 ms | 63632 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>
#define pb push_back
#define x first
#define y second
using namespace std;
const int N = 150005, K = 6, LG = 17;
int n, m, k, q, P[LG][N][K];
int main()
{
memset(P, 63, sizeof(P));
scanf("%d%d%d%d", &k, &n, &m, &q);
for (int i = 1; i <= m; i++)
{
int a, b, t;
scanf("%d%d%d", &a, &b, &t);
P[0][a][b % k] = min(P[0][a][b % k], t);
}
int pw = 1;
for (int i = 1; i < LG; i++)
{
if (pw * k >= n)
break;
for (int j = 0; j < n; j++)
for (int h = 0; h < k; h++)
for (int md = 0; md < k; md++)
P[i][j][h] = min(P[i][j][h], P[i - 1][j][md] + P[i - 1][(j / k + pw) * k + md][h]);
pw <<= 1;
}
for (; q; q --)
{
int a, b, D[K], T[K];
scanf("%d%d", &a, &b);
if (a > b)
{
printf("-1\n");
continue;
}
memset(D, 63, sizeof(D));
D[a % k] = 0;
a = a / k * k;
for (int i = 0; i < LG; i++)
if ((a / k - b / k) & (1 << i))
{
memset(T, 63, sizeof(T));
for (int f = 0; f < k; f ++)
for (int h = 0; h < k; h ++)
T[h] = min(T[h], D[f] + P[i][a + f][h]);
for (int h = 0; h < k; h ++)
D[h] = T[h];
a += (1 << i) * k;
}
if (D[b % k] > (int)(6e8))
printf("-1\n");
else
printf("%d\n", D[b % k]);
}
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... |