# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
298644 | 2020-09-13T17:19:24 Z | errorgorn | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 102 ms | 7036 KB |
#include <cstdio> #include <queue> #include <utility> #include <cstring> using namespace std; typedef pair<int,int> ii; const int SQRTN=300; const int MAXN=30005; int n,k; int w[MAXN]; bool pow[SQRTN][MAXN]; vector<int> power[MAXN]; priority_queue<ii,vector<ii>,greater<ii> > pq; int main(){ scanf("%d%d",&n,&k); int a,b; int s,t; for (int x=0;x<k;x++){ scanf("%d%d",&a,&b); if (x==0) s=a; else if (x==1) t=a; if (b<SQRTN){ if (pow[b][a]) continue; pow[b][a]=true; power[a].push_back(b); } else{ power[a].push_back(b); } } memset(w,127,sizeof(w)); w[s]=0; pq.push(ii(w[s],s)); int node,weight; while (!pq.empty()){ node=pq.top().second,weight=pq.top().first,pq.pop(); //printf("%d %d\n",node,weight); if (w[node]!=weight) continue; if (node==t){ printf("%d\n",weight); return 0; } for (auto &p:power[node]){ for (int x=node-p;x>=0;x-=p){ if (w[x]>weight+(node-x)/p){ w[x]=weight+(node-x)/p; pq.push(ii(w[x],x)); } if (p<SQRTN && pow[p][x]) break; } for (int x=node+p;x<MAXN;x+=p){ if (w[x]>weight+(x-node)/p){ w[x]=weight+(x-node)/p; pq.push(ii(w[x],x)); } if (p<SQRTN && pow[p][x]) break; } } } printf("-1\n"); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1536 KB | Output is correct |
2 | Correct | 1 ms | 1152 KB | Output is correct |
3 | Correct | 1 ms | 1152 KB | Output is correct |
4 | Correct | 1 ms | 1152 KB | Output is correct |
5 | Correct | 2 ms | 1536 KB | Output is correct |
6 | Correct | 2 ms | 1664 KB | Output is correct |
7 | Correct | 1 ms | 1152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1536 KB | Output is correct |
2 | Correct | 1 ms | 1152 KB | Output is correct |
3 | Correct | 1 ms | 1152 KB | Output is correct |
4 | Correct | 1 ms | 1152 KB | Output is correct |
5 | Correct | 2 ms | 1536 KB | Output is correct |
6 | Correct | 2 ms | 1536 KB | Output is correct |
7 | Correct | 1 ms | 1152 KB | Output is correct |
8 | Correct | 2 ms | 1536 KB | Output is correct |
9 | Correct | 2 ms | 1664 KB | Output is correct |
10 | Correct | 6 ms | 2680 KB | Output is correct |
11 | Correct | 3 ms | 1920 KB | Output is correct |
12 | Correct | 4 ms | 1916 KB | Output is correct |
13 | Correct | 1 ms | 1152 KB | Output is correct |
14 | Correct | 22 ms | 3572 KB | Output is correct |
15 | Correct | 19 ms | 3732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1536 KB | Output is correct |
2 | Correct | 1 ms | 1152 KB | Output is correct |
3 | Correct | 1 ms | 1152 KB | Output is correct |
4 | Correct | 1 ms | 1152 KB | Output is correct |
5 | Correct | 3 ms | 1536 KB | Output is correct |
6 | Correct | 2 ms | 1536 KB | Output is correct |
7 | Correct | 1 ms | 1152 KB | Output is correct |
8 | Correct | 2 ms | 1664 KB | Output is correct |
9 | Correct | 2 ms | 1664 KB | Output is correct |
10 | Correct | 6 ms | 2680 KB | Output is correct |
11 | Correct | 3 ms | 1920 KB | Output is correct |
12 | Correct | 3 ms | 1916 KB | Output is correct |
13 | Correct | 1 ms | 1280 KB | Output is correct |
14 | Correct | 21 ms | 3572 KB | Output is correct |
15 | Correct | 20 ms | 3572 KB | Output is correct |
16 | Correct | 2 ms | 1920 KB | Output is correct |
17 | Correct | 9 ms | 3576 KB | Output is correct |
18 | Correct | 2 ms | 1664 KB | Output is correct |
19 | Correct | 2 ms | 1536 KB | Output is correct |
20 | Correct | 2 ms | 1152 KB | Output is correct |
21 | Correct | 2 ms | 1664 KB | Output is correct |
22 | Correct | 1 ms | 1536 KB | Output is correct |
23 | Correct | 11 ms | 2300 KB | Output is correct |
24 | Correct | 9 ms | 2812 KB | Output is correct |
25 | Correct | 3 ms | 1536 KB | Output is correct |
26 | Correct | 4 ms | 2300 KB | Output is correct |
27 | Correct | 5 ms | 2044 KB | Output is correct |
28 | Correct | 9 ms | 1920 KB | Output is correct |
29 | Correct | 33 ms | 3444 KB | Output is correct |
30 | Correct | 15 ms | 2292 KB | Output is correct |
31 | Correct | 21 ms | 2552 KB | Output is correct |
32 | Correct | 14 ms | 1788 KB | Output is correct |
33 | Correct | 45 ms | 3572 KB | Output is correct |
34 | Correct | 20 ms | 3572 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1536 KB | Output is correct |
2 | Correct | 1 ms | 1152 KB | Output is correct |
3 | Correct | 1 ms | 1152 KB | Output is correct |
4 | Correct | 1 ms | 1280 KB | Output is correct |
5 | Correct | 2 ms | 1536 KB | Output is correct |
6 | Correct | 2 ms | 1536 KB | Output is correct |
7 | Correct | 1 ms | 1152 KB | Output is correct |
8 | Correct | 2 ms | 1664 KB | Output is correct |
9 | Correct | 2 ms | 1664 KB | Output is correct |
10 | Correct | 6 ms | 2680 KB | Output is correct |
11 | Correct | 3 ms | 1920 KB | Output is correct |
12 | Correct | 3 ms | 1916 KB | Output is correct |
13 | Correct | 1 ms | 1152 KB | Output is correct |
14 | Correct | 22 ms | 3572 KB | Output is correct |
15 | Correct | 19 ms | 3572 KB | Output is correct |
16 | Correct | 2 ms | 1920 KB | Output is correct |
17 | Correct | 9 ms | 3704 KB | Output is correct |
18 | Correct | 2 ms | 1664 KB | Output is correct |
19 | Correct | 1 ms | 1408 KB | Output is correct |
20 | Correct | 2 ms | 1152 KB | Output is correct |
21 | Correct | 2 ms | 1664 KB | Output is correct |
22 | Correct | 1 ms | 1536 KB | Output is correct |
23 | Correct | 8 ms | 2428 KB | Output is correct |
24 | Correct | 8 ms | 2684 KB | Output is correct |
25 | Correct | 3 ms | 1664 KB | Output is correct |
26 | Correct | 4 ms | 2300 KB | Output is correct |
27 | Correct | 5 ms | 2172 KB | Output is correct |
28 | Correct | 9 ms | 1920 KB | Output is correct |
29 | Correct | 33 ms | 3444 KB | Output is correct |
30 | Correct | 15 ms | 2292 KB | Output is correct |
31 | Correct | 19 ms | 2424 KB | Output is correct |
32 | Correct | 14 ms | 1788 KB | Output is correct |
33 | Correct | 45 ms | 3572 KB | Output is correct |
34 | Correct | 20 ms | 3572 KB | Output is correct |
35 | Correct | 29 ms | 4220 KB | Output is correct |
36 | Correct | 6 ms | 3068 KB | Output is correct |
37 | Correct | 23 ms | 4344 KB | Output is correct |
38 | Correct | 21 ms | 4604 KB | Output is correct |
39 | Correct | 12 ms | 3456 KB | Output is correct |
40 | Correct | 13 ms | 3744 KB | Output is correct |
41 | Correct | 17 ms | 4476 KB | Output is correct |
42 | Correct | 9 ms | 2460 KB | Output is correct |
43 | Correct | 11 ms | 2300 KB | Output is correct |
44 | Correct | 7 ms | 1408 KB | Output is correct |
45 | Correct | 96 ms | 4724 KB | Output is correct |
46 | Correct | 66 ms | 4724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1568 KB | Output is correct |
2 | Correct | 1 ms | 1152 KB | Output is correct |
3 | Correct | 1 ms | 1152 KB | Output is correct |
4 | Correct | 1 ms | 1152 KB | Output is correct |
5 | Correct | 2 ms | 1536 KB | Output is correct |
6 | Correct | 2 ms | 1536 KB | Output is correct |
7 | Correct | 1 ms | 1152 KB | Output is correct |
8 | Correct | 2 ms | 1664 KB | Output is correct |
9 | Correct | 2 ms | 1664 KB | Output is correct |
10 | Correct | 5 ms | 2680 KB | Output is correct |
11 | Correct | 4 ms | 1920 KB | Output is correct |
12 | Correct | 3 ms | 1916 KB | Output is correct |
13 | Correct | 1 ms | 1152 KB | Output is correct |
14 | Correct | 22 ms | 3572 KB | Output is correct |
15 | Correct | 20 ms | 3572 KB | Output is correct |
16 | Correct | 2 ms | 1920 KB | Output is correct |
17 | Correct | 9 ms | 3576 KB | Output is correct |
18 | Correct | 2 ms | 1664 KB | Output is correct |
19 | Correct | 1 ms | 1536 KB | Output is correct |
20 | Correct | 2 ms | 1152 KB | Output is correct |
21 | Correct | 2 ms | 1664 KB | Output is correct |
22 | Correct | 2 ms | 1536 KB | Output is correct |
23 | Correct | 8 ms | 2300 KB | Output is correct |
24 | Correct | 8 ms | 2684 KB | Output is correct |
25 | Correct | 3 ms | 1536 KB | Output is correct |
26 | Correct | 4 ms | 2300 KB | Output is correct |
27 | Correct | 5 ms | 2044 KB | Output is correct |
28 | Correct | 9 ms | 1920 KB | Output is correct |
29 | Correct | 33 ms | 3444 KB | Output is correct |
30 | Correct | 16 ms | 2292 KB | Output is correct |
31 | Correct | 23 ms | 2424 KB | Output is correct |
32 | Correct | 14 ms | 1788 KB | Output is correct |
33 | Correct | 45 ms | 3572 KB | Output is correct |
34 | Correct | 20 ms | 3572 KB | Output is correct |
35 | Correct | 27 ms | 4220 KB | Output is correct |
36 | Correct | 6 ms | 3068 KB | Output is correct |
37 | Correct | 23 ms | 4344 KB | Output is correct |
38 | Correct | 22 ms | 4468 KB | Output is correct |
39 | Correct | 12 ms | 3328 KB | Output is correct |
40 | Correct | 13 ms | 3712 KB | Output is correct |
41 | Correct | 25 ms | 4476 KB | Output is correct |
42 | Correct | 9 ms | 2556 KB | Output is correct |
43 | Correct | 11 ms | 2204 KB | Output is correct |
44 | Correct | 7 ms | 1408 KB | Output is correct |
45 | Correct | 98 ms | 4724 KB | Output is correct |
46 | Correct | 64 ms | 4724 KB | Output is correct |
47 | Correct | 24 ms | 7036 KB | Output is correct |
48 | Correct | 10 ms | 2816 KB | Output is correct |
49 | Correct | 11 ms | 2560 KB | Output is correct |
50 | Correct | 7 ms | 2304 KB | Output is correct |
51 | Correct | 22 ms | 3712 KB | Output is correct |
52 | Correct | 22 ms | 3968 KB | Output is correct |
53 | Correct | 13 ms | 2304 KB | Output is correct |
54 | Correct | 2 ms | 1408 KB | Output is correct |
55 | Correct | 3 ms | 1408 KB | Output is correct |
56 | Correct | 12 ms | 2304 KB | Output is correct |
57 | Correct | 3 ms | 2048 KB | Output is correct |
58 | Correct | 9 ms | 1536 KB | Output is correct |
59 | Correct | 10 ms | 1792 KB | Output is correct |
60 | Correct | 11 ms | 2688 KB | Output is correct |
61 | Correct | 10 ms | 1920 KB | Output is correct |
62 | Correct | 17 ms | 3072 KB | Output is correct |
63 | Correct | 48 ms | 3200 KB | Output is correct |
64 | Correct | 51 ms | 3196 KB | Output is correct |
65 | Correct | 67 ms | 4724 KB | Output is correct |
66 | Correct | 102 ms | 4724 KB | Output is correct |
67 | Correct | 87 ms | 4724 KB | Output is correct |