# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
213629 | 2020-03-26T09:46:41 Z | MKopchev | Toll (BOI17_toll) | C++14 | 160 ms | 101624 KB |
#include<bits/stdc++.h> using namespace std; const int nmax=5e4+42; int k,n,m,q; int dist[20][nmax][5][5]; int dist_1[5][5],dist_2[5][5],dist_3[5][5]; void my_merge() { memset(dist_3,-1,sizeof(dist_3)); for(int i=0;i<k;i++) for(int j=0;j<k;j++) for(int p=0;p<k;p++) if(dist_1[i][j]!=-1&&dist_2[j][p]!=-1) { int is=dist_1[i][j]+dist_2[j][p]; if(dist_3[i][p]==-1)dist_3[i][p]=is; else dist_3[i][p]=min(dist_3[i][p],is); } } int current_dists[5],help[5]; int query() { int u,v; scanf("%i%i",&u,&v); memset(current_dists,-1,sizeof(current_dists)); current_dists[u%k]=0; int beg=u/k,en=v/k; for(int step=19;step>=0;step--) if(beg+(1<<step)<=en) { memset(help,-1,sizeof(help)); for(int j=0;j<k;j++) for(int p=0;p<k;p++) if(current_dists[j]!=-1&&dist[step][beg][j][p]!=-1) { int is=current_dists[j]+dist[step][beg][j][p]; if(help[p]==-1)help[p]=is; else help[p]=min(help[p],is); } for(int j=0;j<k;j++) current_dists[j]=help[j]; beg=beg+(1<<step); } return current_dists[v%k]; } int main() { memset(dist,-1,sizeof(dist)); scanf("%i%i%i%i",&k,&n,&m,&q); int a,b,t; for(int i=1;i<=m;i++) { scanf("%i%i%i",&a,&b,&t); dist[0][a/k][a%k][b%k]=t; } for(int step=1;step<20;step++) { for(int i=0;i+(1<<step)-1<=n/k;i++) { for(int j=0;j<k;j++) for(int p=0;p<k;p++) { dist_1[j][p]=dist[step-1][i][j][p]; dist_2[j][p]=dist[step-1][i+(1<<(step-1))][j][p]; } my_merge(); for(int j=0;j<k;j++) for(int p=0;p<k;p++) dist[step][i][j][p]=dist_3[j][p]; } } for(int i=1;i<=q;i++) printf("%i\n",query()); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 90 ms | 99320 KB | Output is correct |
2 | Correct | 50 ms | 98296 KB | Output is correct |
3 | Correct | 49 ms | 98432 KB | Output is correct |
4 | Correct | 50 ms | 98168 KB | Output is correct |
5 | Correct | 51 ms | 98300 KB | Output is correct |
6 | Correct | 54 ms | 98424 KB | Output is correct |
7 | Correct | 51 ms | 98168 KB | Output is correct |
8 | Correct | 88 ms | 99192 KB | Output is correct |
9 | Correct | 95 ms | 99196 KB | Output is correct |
10 | Correct | 72 ms | 98424 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 102 ms | 99960 KB | Output is correct |
2 | Correct | 50 ms | 98168 KB | Output is correct |
3 | Correct | 54 ms | 98040 KB | Output is correct |
4 | Correct | 49 ms | 98040 KB | Output is correct |
5 | Correct | 49 ms | 98296 KB | Output is correct |
6 | Correct | 55 ms | 98296 KB | Output is correct |
7 | Correct | 54 ms | 98424 KB | Output is correct |
8 | Correct | 55 ms | 98428 KB | Output is correct |
9 | Correct | 95 ms | 99192 KB | Output is correct |
10 | Correct | 124 ms | 100600 KB | Output is correct |
11 | Correct | 114 ms | 100088 KB | Output is correct |
12 | Correct | 104 ms | 99576 KB | Output is correct |
13 | Correct | 129 ms | 100732 KB | Output is correct |
14 | Correct | 96 ms | 99704 KB | Output is correct |
15 | Correct | 104 ms | 99576 KB | Output is correct |
16 | Correct | 106 ms | 99576 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 98296 KB | Output is correct |
2 | Correct | 50 ms | 98296 KB | Output is correct |
3 | Correct | 50 ms | 98296 KB | Output is correct |
4 | Correct | 50 ms | 98428 KB | Output is correct |
5 | Correct | 54 ms | 98300 KB | Output is correct |
6 | Correct | 49 ms | 98296 KB | Output is correct |
7 | Correct | 54 ms | 98296 KB | Output is correct |
8 | Correct | 51 ms | 98296 KB | Output is correct |
9 | Correct | 51 ms | 98296 KB | Output is correct |
10 | Correct | 91 ms | 99064 KB | Output is correct |
11 | Correct | 109 ms | 99832 KB | Output is correct |
12 | Correct | 117 ms | 100472 KB | Output is correct |
13 | Correct | 122 ms | 100728 KB | Output is correct |
14 | Correct | 116 ms | 100088 KB | Output is correct |
15 | Correct | 103 ms | 99448 KB | Output is correct |
16 | Correct | 104 ms | 99448 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 98296 KB | Output is correct |
2 | Correct | 50 ms | 98296 KB | Output is correct |
3 | Correct | 50 ms | 98296 KB | Output is correct |
4 | Correct | 50 ms | 98428 KB | Output is correct |
5 | Correct | 54 ms | 98300 KB | Output is correct |
6 | Correct | 49 ms | 98296 KB | Output is correct |
7 | Correct | 54 ms | 98296 KB | Output is correct |
8 | Correct | 51 ms | 98296 KB | Output is correct |
9 | Correct | 51 ms | 98296 KB | Output is correct |
10 | Correct | 91 ms | 99064 KB | Output is correct |
11 | Correct | 109 ms | 99832 KB | Output is correct |
12 | Correct | 117 ms | 100472 KB | Output is correct |
13 | Correct | 122 ms | 100728 KB | Output is correct |
14 | Correct | 116 ms | 100088 KB | Output is correct |
15 | Correct | 103 ms | 99448 KB | Output is correct |
16 | Correct | 104 ms | 99448 KB | Output is correct |
17 | Correct | 102 ms | 99832 KB | Output is correct |
18 | Correct | 55 ms | 98296 KB | Output is correct |
19 | Correct | 53 ms | 98296 KB | Output is correct |
20 | Correct | 51 ms | 98304 KB | Output is correct |
21 | Correct | 49 ms | 98296 KB | Output is correct |
22 | Correct | 55 ms | 98296 KB | Output is correct |
23 | Correct | 51 ms | 98296 KB | Output is correct |
24 | Correct | 51 ms | 98296 KB | Output is correct |
25 | Correct | 54 ms | 98424 KB | Output is correct |
26 | Correct | 52 ms | 98296 KB | Output is correct |
27 | Correct | 84 ms | 99192 KB | Output is correct |
28 | Correct | 120 ms | 100472 KB | Output is correct |
29 | Correct | 131 ms | 100728 KB | Output is correct |
30 | Correct | 113 ms | 100088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 90 ms | 99320 KB | Output is correct |
2 | Correct | 50 ms | 98296 KB | Output is correct |
3 | Correct | 49 ms | 98432 KB | Output is correct |
4 | Correct | 50 ms | 98168 KB | Output is correct |
5 | Correct | 51 ms | 98300 KB | Output is correct |
6 | Correct | 54 ms | 98424 KB | Output is correct |
7 | Correct | 51 ms | 98168 KB | Output is correct |
8 | Correct | 88 ms | 99192 KB | Output is correct |
9 | Correct | 95 ms | 99196 KB | Output is correct |
10 | Correct | 72 ms | 98424 KB | Output is correct |
11 | Correct | 102 ms | 99960 KB | Output is correct |
12 | Correct | 50 ms | 98168 KB | Output is correct |
13 | Correct | 54 ms | 98040 KB | Output is correct |
14 | Correct | 49 ms | 98040 KB | Output is correct |
15 | Correct | 49 ms | 98296 KB | Output is correct |
16 | Correct | 55 ms | 98296 KB | Output is correct |
17 | Correct | 54 ms | 98424 KB | Output is correct |
18 | Correct | 55 ms | 98428 KB | Output is correct |
19 | Correct | 95 ms | 99192 KB | Output is correct |
20 | Correct | 124 ms | 100600 KB | Output is correct |
21 | Correct | 114 ms | 100088 KB | Output is correct |
22 | Correct | 104 ms | 99576 KB | Output is correct |
23 | Correct | 129 ms | 100732 KB | Output is correct |
24 | Correct | 96 ms | 99704 KB | Output is correct |
25 | Correct | 104 ms | 99576 KB | Output is correct |
26 | Correct | 106 ms | 99576 KB | Output is correct |
27 | Correct | 50 ms | 98296 KB | Output is correct |
28 | Correct | 50 ms | 98296 KB | Output is correct |
29 | Correct | 50 ms | 98296 KB | Output is correct |
30 | Correct | 50 ms | 98428 KB | Output is correct |
31 | Correct | 54 ms | 98300 KB | Output is correct |
32 | Correct | 49 ms | 98296 KB | Output is correct |
33 | Correct | 54 ms | 98296 KB | Output is correct |
34 | Correct | 51 ms | 98296 KB | Output is correct |
35 | Correct | 51 ms | 98296 KB | Output is correct |
36 | Correct | 91 ms | 99064 KB | Output is correct |
37 | Correct | 109 ms | 99832 KB | Output is correct |
38 | Correct | 117 ms | 100472 KB | Output is correct |
39 | Correct | 122 ms | 100728 KB | Output is correct |
40 | Correct | 116 ms | 100088 KB | Output is correct |
41 | Correct | 103 ms | 99448 KB | Output is correct |
42 | Correct | 104 ms | 99448 KB | Output is correct |
43 | Correct | 102 ms | 99832 KB | Output is correct |
44 | Correct | 55 ms | 98296 KB | Output is correct |
45 | Correct | 53 ms | 98296 KB | Output is correct |
46 | Correct | 51 ms | 98304 KB | Output is correct |
47 | Correct | 49 ms | 98296 KB | Output is correct |
48 | Correct | 55 ms | 98296 KB | Output is correct |
49 | Correct | 51 ms | 98296 KB | Output is correct |
50 | Correct | 51 ms | 98296 KB | Output is correct |
51 | Correct | 54 ms | 98424 KB | Output is correct |
52 | Correct | 52 ms | 98296 KB | Output is correct |
53 | Correct | 84 ms | 99192 KB | Output is correct |
54 | Correct | 120 ms | 100472 KB | Output is correct |
55 | Correct | 131 ms | 100728 KB | Output is correct |
56 | Correct | 113 ms | 100088 KB | Output is correct |
57 | Correct | 160 ms | 101624 KB | Output is correct |
58 | Correct | 96 ms | 99192 KB | Output is correct |
59 | Correct | 107 ms | 100088 KB | Output is correct |