# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
182152 | 2020-01-09T12:06:49 Z | Ruxandra985 | Toll (BOI17_toll) | C++14 | 1279 ms | 173228 KB |
#include <bits/stdc++.h> #define INF 2000000000 using namespace std; map <int,int> rmq[20][50010]; map <int , pair <int,int> > mp; int lg[50010] , step[50010]; deque <pair <int,int> > dq; int main() { FILE *fin = stdin; FILE *fout = stdout; int k , n , m , o , x , y, z, i , j , p , len , elem , nod , nr , nrr; fscanf (fin,"%d%d%d%d",&k,&n,&m,&o); for (i=1;i<=m;i++){ fscanf (fin,"%d%d%d",&x,&y,&z); rmq[0][min(x , y)][max(x , y)] = z; } for (i=2;i<=n;i++) lg[i] = 1 + lg[i/2]; for (p=1;(1<<p) <= n/k;p++){ for (i=0;i<=n;i++){ if (i / k + (1 << p) <= n / k){ /// e ok for (j = (i / k + (1 << p)) * k ; j < (i / k + (1 << p) + 1) * k; j++){ for (x = (i / k + (1 << (p-1))) * k ; x < (i / k + (1 << (p-1)) + 1) * k; x++){ if (rmq[p-1][i][x] && rmq[p-1][x][j]){ if (!rmq[p][i][j]) rmq[p][i][j] = rmq[p-1][i][x] + rmq[p-1][x][j]; else rmq[p][i][j] = min(rmq[p][i][j] , rmq[p-1][i][x] + rmq[p-1][x][j]); } } } } else break; } } for (;o;o--){ fscanf (fin,"%d%d",&x,&y); len = (y / k) - (x / k); elem = 0; while (len){ step[++elem] = lg[len]; len -= (1 << lg[len]); } dq.push_back(make_pair(x , 1)); mp[x] = make_pair(o , 0); /// frecventa + cost sa ajungi while (!dq.empty()){ nod = dq.front().first; nr = dq.front().second; nrr = step[nr]; dq.pop_front(); if (nr == elem+1) continue; mp[nod].first = -o; for (j = (nod / k + (1 << nrr)) * k ; j < (nod / k + (1 << nrr) + 1) * k; j++){ if (rmq[nrr][nod][j] && ((mp[j].first != o && mp[j].first != -o) || mp[j].second > mp[nod].second + rmq[nrr][nod][j])){ mp[j].second = mp[nod].second + rmq[nrr][nod][j]; if (mp[j].first != o){ /// nu e ACUM in deque mp[j].first = o; dq.push_back(make_pair(j , nr + 1)); } } } } if ((mp[y].first != o && mp[y].first != -o)) fprintf (fout,"-1\n"); else fprintf (fout,"%d\n",mp[y].second); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 294 ms | 84412 KB | Output is correct |
2 | Correct | 51 ms | 47352 KB | Output is correct |
3 | Correct | 45 ms | 47224 KB | Output is correct |
4 | Correct | 45 ms | 47224 KB | Output is correct |
5 | Correct | 48 ms | 47836 KB | Output is correct |
6 | Correct | 57 ms | 47736 KB | Output is correct |
7 | Correct | 57 ms | 47736 KB | Output is correct |
8 | Correct | 173 ms | 81048 KB | Output is correct |
9 | Correct | 165 ms | 80812 KB | Output is correct |
10 | Correct | 134 ms | 80872 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 402 ms | 111576 KB | Output is correct |
2 | Correct | 46 ms | 47352 KB | Output is correct |
3 | Correct | 46 ms | 47352 KB | Output is correct |
4 | Correct | 45 ms | 47224 KB | Output is correct |
5 | Correct | 45 ms | 47224 KB | Output is correct |
6 | Correct | 45 ms | 47352 KB | Output is correct |
7 | Correct | 52 ms | 47864 KB | Output is correct |
8 | Correct | 107 ms | 48220 KB | Output is correct |
9 | Correct | 164 ms | 81144 KB | Output is correct |
10 | Correct | 812 ms | 143736 KB | Output is correct |
11 | Correct | 499 ms | 115268 KB | Output is correct |
12 | Correct | 381 ms | 134416 KB | Output is correct |
13 | Correct | 879 ms | 133068 KB | Output is correct |
14 | Correct | 401 ms | 102136 KB | Output is correct |
15 | Correct | 748 ms | 131628 KB | Output is correct |
16 | Correct | 749 ms | 131504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 47224 KB | Output is correct |
2 | Correct | 45 ms | 47352 KB | Output is correct |
3 | Correct | 45 ms | 47224 KB | Output is correct |
4 | Correct | 43 ms | 47356 KB | Output is correct |
5 | Correct | 45 ms | 47352 KB | Output is correct |
6 | Correct | 48 ms | 47708 KB | Output is correct |
7 | Correct | 49 ms | 48120 KB | Output is correct |
8 | Correct | 60 ms | 49016 KB | Output is correct |
9 | Correct | 57 ms | 48632 KB | Output is correct |
10 | Correct | 157 ms | 80632 KB | Output is correct |
11 | Correct | 346 ms | 113568 KB | Output is correct |
12 | Correct | 533 ms | 141712 KB | Output is correct |
13 | Correct | 541 ms | 141916 KB | Output is correct |
14 | Correct | 509 ms | 141244 KB | Output is correct |
15 | Correct | 615 ms | 130680 KB | Output is correct |
16 | Correct | 611 ms | 130772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 47224 KB | Output is correct |
2 | Correct | 45 ms | 47352 KB | Output is correct |
3 | Correct | 45 ms | 47224 KB | Output is correct |
4 | Correct | 43 ms | 47356 KB | Output is correct |
5 | Correct | 45 ms | 47352 KB | Output is correct |
6 | Correct | 48 ms | 47708 KB | Output is correct |
7 | Correct | 49 ms | 48120 KB | Output is correct |
8 | Correct | 60 ms | 49016 KB | Output is correct |
9 | Correct | 57 ms | 48632 KB | Output is correct |
10 | Correct | 157 ms | 80632 KB | Output is correct |
11 | Correct | 346 ms | 113568 KB | Output is correct |
12 | Correct | 533 ms | 141712 KB | Output is correct |
13 | Correct | 541 ms | 141916 KB | Output is correct |
14 | Correct | 509 ms | 141244 KB | Output is correct |
15 | Correct | 615 ms | 130680 KB | Output is correct |
16 | Correct | 611 ms | 130772 KB | Output is correct |
17 | Correct | 387 ms | 115188 KB | Output is correct |
18 | Correct | 44 ms | 47352 KB | Output is correct |
19 | Correct | 46 ms | 47328 KB | Output is correct |
20 | Correct | 48 ms | 47296 KB | Output is correct |
21 | Correct | 46 ms | 47228 KB | Output is correct |
22 | Correct | 49 ms | 47352 KB | Output is correct |
23 | Correct | 49 ms | 47992 KB | Output is correct |
24 | Correct | 70 ms | 48248 KB | Output is correct |
25 | Correct | 130 ms | 49204 KB | Output is correct |
26 | Correct | 102 ms | 48760 KB | Output is correct |
27 | Correct | 159 ms | 81116 KB | Output is correct |
28 | Correct | 624 ms | 143608 KB | Output is correct |
29 | Correct | 631 ms | 143992 KB | Output is correct |
30 | Correct | 550 ms | 139420 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 294 ms | 84412 KB | Output is correct |
2 | Correct | 51 ms | 47352 KB | Output is correct |
3 | Correct | 45 ms | 47224 KB | Output is correct |
4 | Correct | 45 ms | 47224 KB | Output is correct |
5 | Correct | 48 ms | 47836 KB | Output is correct |
6 | Correct | 57 ms | 47736 KB | Output is correct |
7 | Correct | 57 ms | 47736 KB | Output is correct |
8 | Correct | 173 ms | 81048 KB | Output is correct |
9 | Correct | 165 ms | 80812 KB | Output is correct |
10 | Correct | 134 ms | 80872 KB | Output is correct |
11 | Correct | 402 ms | 111576 KB | Output is correct |
12 | Correct | 46 ms | 47352 KB | Output is correct |
13 | Correct | 46 ms | 47352 KB | Output is correct |
14 | Correct | 45 ms | 47224 KB | Output is correct |
15 | Correct | 45 ms | 47224 KB | Output is correct |
16 | Correct | 45 ms | 47352 KB | Output is correct |
17 | Correct | 52 ms | 47864 KB | Output is correct |
18 | Correct | 107 ms | 48220 KB | Output is correct |
19 | Correct | 164 ms | 81144 KB | Output is correct |
20 | Correct | 812 ms | 143736 KB | Output is correct |
21 | Correct | 499 ms | 115268 KB | Output is correct |
22 | Correct | 381 ms | 134416 KB | Output is correct |
23 | Correct | 879 ms | 133068 KB | Output is correct |
24 | Correct | 401 ms | 102136 KB | Output is correct |
25 | Correct | 748 ms | 131628 KB | Output is correct |
26 | Correct | 749 ms | 131504 KB | Output is correct |
27 | Correct | 46 ms | 47224 KB | Output is correct |
28 | Correct | 45 ms | 47352 KB | Output is correct |
29 | Correct | 45 ms | 47224 KB | Output is correct |
30 | Correct | 43 ms | 47356 KB | Output is correct |
31 | Correct | 45 ms | 47352 KB | Output is correct |
32 | Correct | 48 ms | 47708 KB | Output is correct |
33 | Correct | 49 ms | 48120 KB | Output is correct |
34 | Correct | 60 ms | 49016 KB | Output is correct |
35 | Correct | 57 ms | 48632 KB | Output is correct |
36 | Correct | 157 ms | 80632 KB | Output is correct |
37 | Correct | 346 ms | 113568 KB | Output is correct |
38 | Correct | 533 ms | 141712 KB | Output is correct |
39 | Correct | 541 ms | 141916 KB | Output is correct |
40 | Correct | 509 ms | 141244 KB | Output is correct |
41 | Correct | 615 ms | 130680 KB | Output is correct |
42 | Correct | 611 ms | 130772 KB | Output is correct |
43 | Correct | 387 ms | 115188 KB | Output is correct |
44 | Correct | 44 ms | 47352 KB | Output is correct |
45 | Correct | 46 ms | 47328 KB | Output is correct |
46 | Correct | 48 ms | 47296 KB | Output is correct |
47 | Correct | 46 ms | 47228 KB | Output is correct |
48 | Correct | 49 ms | 47352 KB | Output is correct |
49 | Correct | 49 ms | 47992 KB | Output is correct |
50 | Correct | 70 ms | 48248 KB | Output is correct |
51 | Correct | 130 ms | 49204 KB | Output is correct |
52 | Correct | 102 ms | 48760 KB | Output is correct |
53 | Correct | 159 ms | 81116 KB | Output is correct |
54 | Correct | 624 ms | 143608 KB | Output is correct |
55 | Correct | 631 ms | 143992 KB | Output is correct |
56 | Correct | 550 ms | 139420 KB | Output is correct |
57 | Correct | 1279 ms | 173228 KB | Output is correct |
58 | Correct | 174 ms | 81912 KB | Output is correct |
59 | Correct | 535 ms | 116372 KB | Output is correct |