# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
912329 |
2024-01-19T10:02:50 Z |
imarn |
Toll (BOI17_toll) |
C++14 |
|
140 ms |
167000 KB |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
using namespace std;
ll dp[50001][17][5][5];int k;
void pre(int i,int j,int ii,int jj,int iii,int jjj){
for(int x=0;x<k;x++){
for(int y=0;y<k;y++){
for(int z=0;z<k;z++){
dp[i][j][x][y]=min(dp[i][j][x][y],dp[ii][jj][x][z]+dp[iii][jjj][z][y]);
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m,o;cin>>k>>n>>m>>o;
for(int i=0;i<50001;i++)for(int j=0;j<17;j++)for(int t=0;t<5;t++)for(int l=0;l<5;l++)dp[i][j][t][l]=1e10;
while(m--){
int a,b,t;cin>>a>>b>>t;
dp[a/k][0][a%k][b%k]=t;
}
for(int j=1;j<17;j++){
for(int i=0;i+(1<<j)<(n+k-1)/k;i++){
pre(i,j,i,j-1,i+(1<<j-1),j-1);
}
}ll ans[5]={0},tmp[5]={0};
while(o--){
int a,b;cin>>a>>b;for(int i=0;i<5;i++)ans[i]=1e10;ans[a%k]=0;
int cur=a/k,dest=b/k;
for(int i=16;i>=0;i--){
if(cur+(1<<i)<=dest){
for(int x=0;x<k;x++)tmp[x]=1e10;
for(int y=0;y<k;y++){
for(int z=0;z<k;z++){
tmp[y]=min(tmp[y],ans[z]+dp[cur][i][z][y]);
}
}for(int x=0;x<k;x++)ans[x]=tmp[x];
cur+=(1<<i);
}
}cout<<(ans[b%k]>=1e10?-1:ans[b%k])<<'\n';
}
}
Compilation message
toll.cpp: In function 'int main()':
toll.cpp:30:34: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
30 | pre(i,j,i,j-1,i+(1<<j-1),j-1);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
166776 KB |
Output is correct |
2 |
Correct |
33 ms |
166708 KB |
Output is correct |
3 |
Correct |
33 ms |
166748 KB |
Output is correct |
4 |
Correct |
33 ms |
166656 KB |
Output is correct |
5 |
Correct |
34 ms |
166756 KB |
Output is correct |
6 |
Correct |
34 ms |
166588 KB |
Output is correct |
7 |
Correct |
33 ms |
166676 KB |
Output is correct |
8 |
Correct |
71 ms |
166764 KB |
Output is correct |
9 |
Correct |
70 ms |
166796 KB |
Output is correct |
10 |
Correct |
54 ms |
166688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
166772 KB |
Output is correct |
2 |
Correct |
33 ms |
166708 KB |
Output is correct |
3 |
Correct |
33 ms |
166712 KB |
Output is correct |
4 |
Correct |
32 ms |
166748 KB |
Output is correct |
5 |
Correct |
32 ms |
166724 KB |
Output is correct |
6 |
Correct |
31 ms |
166544 KB |
Output is correct |
7 |
Correct |
37 ms |
166736 KB |
Output is correct |
8 |
Correct |
34 ms |
166748 KB |
Output is correct |
9 |
Correct |
67 ms |
166776 KB |
Output is correct |
10 |
Correct |
98 ms |
166772 KB |
Output is correct |
11 |
Correct |
136 ms |
166780 KB |
Output is correct |
12 |
Correct |
92 ms |
166764 KB |
Output is correct |
13 |
Correct |
76 ms |
166980 KB |
Output is correct |
14 |
Correct |
75 ms |
166776 KB |
Output is correct |
15 |
Correct |
58 ms |
166776 KB |
Output is correct |
16 |
Correct |
73 ms |
166780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
166744 KB |
Output is correct |
2 |
Correct |
31 ms |
166684 KB |
Output is correct |
3 |
Correct |
35 ms |
166740 KB |
Output is correct |
4 |
Correct |
32 ms |
166740 KB |
Output is correct |
5 |
Correct |
35 ms |
166736 KB |
Output is correct |
6 |
Correct |
35 ms |
166728 KB |
Output is correct |
7 |
Correct |
32 ms |
166748 KB |
Output is correct |
8 |
Correct |
35 ms |
166748 KB |
Output is correct |
9 |
Correct |
34 ms |
166740 KB |
Output is correct |
10 |
Correct |
66 ms |
166776 KB |
Output is correct |
11 |
Correct |
113 ms |
166772 KB |
Output is correct |
12 |
Correct |
111 ms |
166776 KB |
Output is correct |
13 |
Correct |
140 ms |
166744 KB |
Output is correct |
14 |
Correct |
106 ms |
167000 KB |
Output is correct |
15 |
Correct |
58 ms |
166736 KB |
Output is correct |
16 |
Correct |
56 ms |
166748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
166744 KB |
Output is correct |
2 |
Correct |
31 ms |
166684 KB |
Output is correct |
3 |
Correct |
35 ms |
166740 KB |
Output is correct |
4 |
Correct |
32 ms |
166740 KB |
Output is correct |
5 |
Correct |
35 ms |
166736 KB |
Output is correct |
6 |
Correct |
35 ms |
166728 KB |
Output is correct |
7 |
Correct |
32 ms |
166748 KB |
Output is correct |
8 |
Correct |
35 ms |
166748 KB |
Output is correct |
9 |
Correct |
34 ms |
166740 KB |
Output is correct |
10 |
Correct |
66 ms |
166776 KB |
Output is correct |
11 |
Correct |
113 ms |
166772 KB |
Output is correct |
12 |
Correct |
111 ms |
166776 KB |
Output is correct |
13 |
Correct |
140 ms |
166744 KB |
Output is correct |
14 |
Correct |
106 ms |
167000 KB |
Output is correct |
15 |
Correct |
58 ms |
166736 KB |
Output is correct |
16 |
Correct |
56 ms |
166748 KB |
Output is correct |
17 |
Correct |
107 ms |
166800 KB |
Output is correct |
18 |
Correct |
31 ms |
166736 KB |
Output is correct |
19 |
Correct |
32 ms |
166748 KB |
Output is correct |
20 |
Correct |
31 ms |
166580 KB |
Output is correct |
21 |
Correct |
32 ms |
166740 KB |
Output is correct |
22 |
Correct |
32 ms |
166748 KB |
Output is correct |
23 |
Correct |
33 ms |
166740 KB |
Output is correct |
24 |
Correct |
33 ms |
166772 KB |
Output is correct |
25 |
Correct |
34 ms |
166740 KB |
Output is correct |
26 |
Correct |
34 ms |
166748 KB |
Output is correct |
27 |
Correct |
62 ms |
166776 KB |
Output is correct |
28 |
Correct |
86 ms |
166800 KB |
Output is correct |
29 |
Correct |
88 ms |
166748 KB |
Output is correct |
30 |
Correct |
98 ms |
166736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
166776 KB |
Output is correct |
2 |
Correct |
33 ms |
166708 KB |
Output is correct |
3 |
Correct |
33 ms |
166748 KB |
Output is correct |
4 |
Correct |
33 ms |
166656 KB |
Output is correct |
5 |
Correct |
34 ms |
166756 KB |
Output is correct |
6 |
Correct |
34 ms |
166588 KB |
Output is correct |
7 |
Correct |
33 ms |
166676 KB |
Output is correct |
8 |
Correct |
71 ms |
166764 KB |
Output is correct |
9 |
Correct |
70 ms |
166796 KB |
Output is correct |
10 |
Correct |
54 ms |
166688 KB |
Output is correct |
11 |
Correct |
128 ms |
166772 KB |
Output is correct |
12 |
Correct |
33 ms |
166708 KB |
Output is correct |
13 |
Correct |
33 ms |
166712 KB |
Output is correct |
14 |
Correct |
32 ms |
166748 KB |
Output is correct |
15 |
Correct |
32 ms |
166724 KB |
Output is correct |
16 |
Correct |
31 ms |
166544 KB |
Output is correct |
17 |
Correct |
37 ms |
166736 KB |
Output is correct |
18 |
Correct |
34 ms |
166748 KB |
Output is correct |
19 |
Correct |
67 ms |
166776 KB |
Output is correct |
20 |
Correct |
98 ms |
166772 KB |
Output is correct |
21 |
Correct |
136 ms |
166780 KB |
Output is correct |
22 |
Correct |
92 ms |
166764 KB |
Output is correct |
23 |
Correct |
76 ms |
166980 KB |
Output is correct |
24 |
Correct |
75 ms |
166776 KB |
Output is correct |
25 |
Correct |
58 ms |
166776 KB |
Output is correct |
26 |
Correct |
73 ms |
166780 KB |
Output is correct |
27 |
Correct |
32 ms |
166744 KB |
Output is correct |
28 |
Correct |
31 ms |
166684 KB |
Output is correct |
29 |
Correct |
35 ms |
166740 KB |
Output is correct |
30 |
Correct |
32 ms |
166740 KB |
Output is correct |
31 |
Correct |
35 ms |
166736 KB |
Output is correct |
32 |
Correct |
35 ms |
166728 KB |
Output is correct |
33 |
Correct |
32 ms |
166748 KB |
Output is correct |
34 |
Correct |
35 ms |
166748 KB |
Output is correct |
35 |
Correct |
34 ms |
166740 KB |
Output is correct |
36 |
Correct |
66 ms |
166776 KB |
Output is correct |
37 |
Correct |
113 ms |
166772 KB |
Output is correct |
38 |
Correct |
111 ms |
166776 KB |
Output is correct |
39 |
Correct |
140 ms |
166744 KB |
Output is correct |
40 |
Correct |
106 ms |
167000 KB |
Output is correct |
41 |
Correct |
58 ms |
166736 KB |
Output is correct |
42 |
Correct |
56 ms |
166748 KB |
Output is correct |
43 |
Correct |
107 ms |
166800 KB |
Output is correct |
44 |
Correct |
31 ms |
166736 KB |
Output is correct |
45 |
Correct |
32 ms |
166748 KB |
Output is correct |
46 |
Correct |
31 ms |
166580 KB |
Output is correct |
47 |
Correct |
32 ms |
166740 KB |
Output is correct |
48 |
Correct |
32 ms |
166748 KB |
Output is correct |
49 |
Correct |
33 ms |
166740 KB |
Output is correct |
50 |
Correct |
33 ms |
166772 KB |
Output is correct |
51 |
Correct |
34 ms |
166740 KB |
Output is correct |
52 |
Correct |
34 ms |
166748 KB |
Output is correct |
53 |
Correct |
62 ms |
166776 KB |
Output is correct |
54 |
Correct |
86 ms |
166800 KB |
Output is correct |
55 |
Correct |
88 ms |
166748 KB |
Output is correct |
56 |
Correct |
98 ms |
166736 KB |
Output is correct |
57 |
Correct |
96 ms |
166748 KB |
Output is correct |
58 |
Correct |
69 ms |
166748 KB |
Output is correct |
59 |
Correct |
110 ms |
166800 KB |
Output is correct |