# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1063363 |
2024-08-17T17:20:47 Z |
I_FloPPed21 |
Toll (BOI17_toll) |
C++14 |
|
85 ms |
86868 KB |
#include <bits/stdc++.h>
using namespace std;
int dp[50005][17][5][5],n,k,m,q,temp[5][5],ans[5][5];
void combine(int target[5][5],int a[5][5],int b[5][5])
{
for(int x=0; x<k; x++)
for(int y=0; y<k; y++)
{
for(int z=0; z<k; z++)
{
target[x][y]=min(target[x][y],a[x][z]+b[z][y]);
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>k>>n>>m>>q;
for(int i=0; i<n; i++)
{
for(int j=0; j<17; j++)
for(int x=0; x<k; x++)
for(int y=0; y<k; y++)
dp[i][j][x][y] =5e8+1;
}
for(int i=0; i < m; i++)
{
int a,b,c;
cin>>a>>b>>c;
dp[a/k][0][a%k][b%k]=c;
}
for(int i=1; i<17; i++)
{
for(int j=0; j+(1<<i)<(n+k-1)/k; j++)
{
combine(dp[j][i],dp[j][i-1],dp[j+(1<<i-1)][i-1]);
}
}
while(q--)
{
int a,b;
cin>>a>>b;
int curent=a/k;
int dest=b/k;
for(int i=0; i<k; i++)
for(int j=0; j<k; j++)
{
ans[i][j] =5e8+1;
temp[i][j] =5e8+1;
}
for(int i = 0 ; i <5; i++)
ans[i][i] =0;
for(int i =16; i>=0; i--)
{
if(curent+(1<<i) >dest)
continue;
combine(temp,ans,dp[curent][i]);
for(int t=0; t<k; t++)
for(int j=0; j<k; j++)
{
ans[t][j]=temp[t][j];
temp[t][j] =5e8+1;
}
curent+=(1<<i);
}
if(ans[a%k][b%k]==5e8+1)
cout<<-1<<'\n';
else
cout<<ans[a%k][b%k]<<'\n';
}
return 0;
}
Compilation message
toll.cpp: In function 'int main()':
toll.cpp:39:51: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
39 | combine(dp[j][i],dp[j][i-1],dp[j+(1<<i-1)][i-1]);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
84560 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
2016 KB |
Output is correct |
6 |
Correct |
1 ms |
2140 KB |
Output is correct |
7 |
Correct |
1 ms |
2140 KB |
Output is correct |
8 |
Correct |
51 ms |
84400 KB |
Output is correct |
9 |
Correct |
50 ms |
84316 KB |
Output is correct |
10 |
Correct |
38 ms |
83640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
85268 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
2216 KB |
Output is correct |
8 |
Correct |
4 ms |
2140 KB |
Output is correct |
9 |
Correct |
49 ms |
84484 KB |
Output is correct |
10 |
Correct |
77 ms |
85840 KB |
Output is correct |
11 |
Correct |
64 ms |
85336 KB |
Output is correct |
12 |
Correct |
67 ms |
84816 KB |
Output is correct |
13 |
Correct |
59 ms |
52560 KB |
Output is correct |
14 |
Correct |
40 ms |
51792 KB |
Output is correct |
15 |
Correct |
45 ms |
51540 KB |
Output is correct |
16 |
Correct |
45 ms |
51560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
2140 KB |
Output is correct |
7 |
Correct |
1 ms |
2136 KB |
Output is correct |
8 |
Correct |
2 ms |
2140 KB |
Output is correct |
9 |
Correct |
2 ms |
2140 KB |
Output is correct |
10 |
Correct |
47 ms |
84304 KB |
Output is correct |
11 |
Correct |
56 ms |
85072 KB |
Output is correct |
12 |
Correct |
68 ms |
85584 KB |
Output is correct |
13 |
Correct |
73 ms |
85840 KB |
Output is correct |
14 |
Correct |
63 ms |
85328 KB |
Output is correct |
15 |
Correct |
45 ms |
51280 KB |
Output is correct |
16 |
Correct |
44 ms |
51280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
2140 KB |
Output is correct |
7 |
Correct |
1 ms |
2136 KB |
Output is correct |
8 |
Correct |
2 ms |
2140 KB |
Output is correct |
9 |
Correct |
2 ms |
2140 KB |
Output is correct |
10 |
Correct |
47 ms |
84304 KB |
Output is correct |
11 |
Correct |
56 ms |
85072 KB |
Output is correct |
12 |
Correct |
68 ms |
85584 KB |
Output is correct |
13 |
Correct |
73 ms |
85840 KB |
Output is correct |
14 |
Correct |
63 ms |
85328 KB |
Output is correct |
15 |
Correct |
45 ms |
51280 KB |
Output is correct |
16 |
Correct |
44 ms |
51280 KB |
Output is correct |
17 |
Correct |
59 ms |
85008 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
2008 KB |
Output is correct |
24 |
Correct |
2 ms |
2140 KB |
Output is correct |
25 |
Correct |
4 ms |
2140 KB |
Output is correct |
26 |
Correct |
3 ms |
2188 KB |
Output is correct |
27 |
Correct |
47 ms |
84444 KB |
Output is correct |
28 |
Correct |
67 ms |
85592 KB |
Output is correct |
29 |
Correct |
71 ms |
85892 KB |
Output is correct |
30 |
Correct |
68 ms |
85332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
84560 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
2016 KB |
Output is correct |
6 |
Correct |
1 ms |
2140 KB |
Output is correct |
7 |
Correct |
1 ms |
2140 KB |
Output is correct |
8 |
Correct |
51 ms |
84400 KB |
Output is correct |
9 |
Correct |
50 ms |
84316 KB |
Output is correct |
10 |
Correct |
38 ms |
83640 KB |
Output is correct |
11 |
Correct |
63 ms |
85268 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
2216 KB |
Output is correct |
18 |
Correct |
4 ms |
2140 KB |
Output is correct |
19 |
Correct |
49 ms |
84484 KB |
Output is correct |
20 |
Correct |
77 ms |
85840 KB |
Output is correct |
21 |
Correct |
64 ms |
85336 KB |
Output is correct |
22 |
Correct |
67 ms |
84816 KB |
Output is correct |
23 |
Correct |
59 ms |
52560 KB |
Output is correct |
24 |
Correct |
40 ms |
51792 KB |
Output is correct |
25 |
Correct |
45 ms |
51540 KB |
Output is correct |
26 |
Correct |
45 ms |
51560 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
2140 KB |
Output is correct |
33 |
Correct |
1 ms |
2136 KB |
Output is correct |
34 |
Correct |
2 ms |
2140 KB |
Output is correct |
35 |
Correct |
2 ms |
2140 KB |
Output is correct |
36 |
Correct |
47 ms |
84304 KB |
Output is correct |
37 |
Correct |
56 ms |
85072 KB |
Output is correct |
38 |
Correct |
68 ms |
85584 KB |
Output is correct |
39 |
Correct |
73 ms |
85840 KB |
Output is correct |
40 |
Correct |
63 ms |
85328 KB |
Output is correct |
41 |
Correct |
45 ms |
51280 KB |
Output is correct |
42 |
Correct |
44 ms |
51280 KB |
Output is correct |
43 |
Correct |
59 ms |
85008 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
2 ms |
2008 KB |
Output is correct |
50 |
Correct |
2 ms |
2140 KB |
Output is correct |
51 |
Correct |
4 ms |
2140 KB |
Output is correct |
52 |
Correct |
3 ms |
2188 KB |
Output is correct |
53 |
Correct |
47 ms |
84444 KB |
Output is correct |
54 |
Correct |
67 ms |
85592 KB |
Output is correct |
55 |
Correct |
71 ms |
85892 KB |
Output is correct |
56 |
Correct |
68 ms |
85332 KB |
Output is correct |
57 |
Correct |
82 ms |
86868 KB |
Output is correct |
58 |
Correct |
52 ms |
84524 KB |
Output is correct |
59 |
Correct |
85 ms |
85376 KB |
Output is correct |