# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245149 | 2020-07-05T15:51:41 Z | m3r8 | Toll (BOI17_toll) | C++14 | 499 ms | 34808 KB |
#include <stdio.h> #define N 100100 int bst[N][17][5]; int nm[N][17][5]; int adj[N][5]; int k,n; int bb[5]; int nxt[5]; int solve(int akt, int en){ //printf("%d %d %d\n",akt,en,bb[en%k]); int mx = -1; if(akt == en/k)return bb[en%k]; for(int i = 15;i>=0;i--){ if(nm[akt*k][i][0]/k <= en/k){ //printf("test %d %d\n",i,nm[akt*k][i][0]/k); for(int j1 = 0;j1<k;j1++){ nxt[j1] = -1; for(int j2 = 0;j2<k;j2++){ if(bb[j2] != -1 && bst[akt*k+j2][i][j1] != -1){ int tmp = bb[j2] + bst[akt*k+j2][i][j1]; if(nxt[j1] == -1 ||nxt[j1] > tmp)nxt[j1] = tmp; }; }; }; for(int j = 0;j<k;j++)bb[j] = nxt[j]; return solve(nm[akt*k][i][0]/k,en); break; }; }; }; int calc(int st, int p, int jk){ if(st > n){ return -1; }; if(bst[st][p][jk])return bst[st][p][jk]; if(p == 0){ if(adj[st][jk])bst[st][p][jk] = adj[st][jk]; else bst[st][p][jk] = -1; nm[st][p][jk] = (st/k + 1)*k + jk; return bst[st][p][jk]; }else{ int mx = -1; for(int i = 0;i<k;i++){ int tmp1 = calc(st,p-1,i); int tmp2; tmp2 = calc(nm[st][p-1][i],p-1,jk); if(tmp1 != -1){ if(tmp2 != -1){ if(mx == -1 || mx > tmp1 + tmp2){ mx = tmp1 + tmp2; }; }; }; }; bst[st][p][jk] = mx; nm[st][p][jk] = (st/k + (1 << p)) * k + jk; return bst[st][p][jk]; }; }; int main(void){ int m,o; scanf("%d %d %d %d",&k,&n,&m,&o); int a,b,t; for(int i = 0;i<m;i++){ scanf("%d %d %d",&a,&b,&t); adj[a][b%k] = t; }; for(int i = 0;i<16;i++){ for(int j = 0;j<k;j++){ for(int l = 0;l<n;l++){ int tmp = calc(l,i,j); //printf("%d %d %d %d %d\n",l,j,i,tmp,nm[l][i][j]); }; }; }; for(int i = 0;i<o;i++){ scanf("%d %d",&a,&b); for(int j = 0;j<k;j++){ bb[j] = -1; }; bb[a%k] = 0; printf("%d\n",solve(a/k,b)); }; return 0; };
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 34680 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 6 ms | 1024 KB | Output is correct |
6 | Correct | 6 ms | 1024 KB | Output is correct |
7 | Correct | 8 ms | 1024 KB | Output is correct |
8 | Correct | 109 ms | 34560 KB | Output is correct |
9 | Correct | 111 ms | 34552 KB | Output is correct |
10 | Correct | 91 ms | 33632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 194 ms | 34552 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 13 ms | 1024 KB | Output is correct |
8 | Correct | 15 ms | 1152 KB | Output is correct |
9 | Correct | 104 ms | 34552 KB | Output is correct |
10 | Correct | 297 ms | 34680 KB | Output is correct |
11 | Correct | 208 ms | 34680 KB | Output is correct |
12 | Correct | 284 ms | 34680 KB | Output is correct |
13 | Correct | 305 ms | 20856 KB | Output is correct |
14 | Correct | 173 ms | 20856 KB | Output is correct |
15 | Correct | 311 ms | 20984 KB | Output is correct |
16 | Correct | 304 ms | 20920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 1024 KB | Output is correct |
7 | Correct | 6 ms | 896 KB | Output is correct |
8 | Correct | 10 ms | 1024 KB | Output is correct |
9 | Correct | 11 ms | 1024 KB | Output is correct |
10 | Correct | 103 ms | 34552 KB | Output is correct |
11 | Correct | 185 ms | 34552 KB | Output is correct |
12 | Correct | 290 ms | 34680 KB | Output is correct |
13 | Correct | 311 ms | 34680 KB | Output is correct |
14 | Correct | 274 ms | 34680 KB | Output is correct |
15 | Correct | 295 ms | 20992 KB | Output is correct |
16 | Correct | 297 ms | 20856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 1024 KB | Output is correct |
7 | Correct | 6 ms | 896 KB | Output is correct |
8 | Correct | 10 ms | 1024 KB | Output is correct |
9 | Correct | 11 ms | 1024 KB | Output is correct |
10 | Correct | 103 ms | 34552 KB | Output is correct |
11 | Correct | 185 ms | 34552 KB | Output is correct |
12 | Correct | 290 ms | 34680 KB | Output is correct |
13 | Correct | 311 ms | 34680 KB | Output is correct |
14 | Correct | 274 ms | 34680 KB | Output is correct |
15 | Correct | 295 ms | 20992 KB | Output is correct |
16 | Correct | 297 ms | 20856 KB | Output is correct |
17 | Correct | 193 ms | 34612 KB | Output is correct |
18 | Correct | 4 ms | 384 KB | Output is correct |
19 | Correct | 4 ms | 384 KB | Output is correct |
20 | Correct | 4 ms | 384 KB | Output is correct |
21 | Correct | 4 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 8 ms | 1024 KB | Output is correct |
24 | Correct | 10 ms | 1152 KB | Output is correct |
25 | Correct | 14 ms | 1024 KB | Output is correct |
26 | Correct | 13 ms | 1024 KB | Output is correct |
27 | Correct | 99 ms | 34552 KB | Output is correct |
28 | Correct | 291 ms | 34680 KB | Output is correct |
29 | Correct | 336 ms | 34680 KB | Output is correct |
30 | Correct | 286 ms | 34680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 34680 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 4 ms | 384 KB | Output is correct |
5 | Correct | 6 ms | 1024 KB | Output is correct |
6 | Correct | 6 ms | 1024 KB | Output is correct |
7 | Correct | 8 ms | 1024 KB | Output is correct |
8 | Correct | 109 ms | 34560 KB | Output is correct |
9 | Correct | 111 ms | 34552 KB | Output is correct |
10 | Correct | 91 ms | 33632 KB | Output is correct |
11 | Correct | 194 ms | 34552 KB | Output is correct |
12 | Correct | 4 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 384 KB | Output is correct |
15 | Correct | 4 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 13 ms | 1024 KB | Output is correct |
18 | Correct | 15 ms | 1152 KB | Output is correct |
19 | Correct | 104 ms | 34552 KB | Output is correct |
20 | Correct | 297 ms | 34680 KB | Output is correct |
21 | Correct | 208 ms | 34680 KB | Output is correct |
22 | Correct | 284 ms | 34680 KB | Output is correct |
23 | Correct | 305 ms | 20856 KB | Output is correct |
24 | Correct | 173 ms | 20856 KB | Output is correct |
25 | Correct | 311 ms | 20984 KB | Output is correct |
26 | Correct | 304 ms | 20920 KB | Output is correct |
27 | Correct | 4 ms | 384 KB | Output is correct |
28 | Correct | 4 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 4 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 1024 KB | Output is correct |
33 | Correct | 6 ms | 896 KB | Output is correct |
34 | Correct | 10 ms | 1024 KB | Output is correct |
35 | Correct | 11 ms | 1024 KB | Output is correct |
36 | Correct | 103 ms | 34552 KB | Output is correct |
37 | Correct | 185 ms | 34552 KB | Output is correct |
38 | Correct | 290 ms | 34680 KB | Output is correct |
39 | Correct | 311 ms | 34680 KB | Output is correct |
40 | Correct | 274 ms | 34680 KB | Output is correct |
41 | Correct | 295 ms | 20992 KB | Output is correct |
42 | Correct | 297 ms | 20856 KB | Output is correct |
43 | Correct | 193 ms | 34612 KB | Output is correct |
44 | Correct | 4 ms | 384 KB | Output is correct |
45 | Correct | 4 ms | 384 KB | Output is correct |
46 | Correct | 4 ms | 384 KB | Output is correct |
47 | Correct | 4 ms | 384 KB | Output is correct |
48 | Correct | 5 ms | 384 KB | Output is correct |
49 | Correct | 8 ms | 1024 KB | Output is correct |
50 | Correct | 10 ms | 1152 KB | Output is correct |
51 | Correct | 14 ms | 1024 KB | Output is correct |
52 | Correct | 13 ms | 1024 KB | Output is correct |
53 | Correct | 99 ms | 34552 KB | Output is correct |
54 | Correct | 291 ms | 34680 KB | Output is correct |
55 | Correct | 336 ms | 34680 KB | Output is correct |
56 | Correct | 286 ms | 34680 KB | Output is correct |
57 | Correct | 499 ms | 34808 KB | Output is correct |
58 | Correct | 110 ms | 34552 KB | Output is correct |
59 | Correct | 206 ms | 34680 KB | Output is correct |