# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
146014 | 2019-08-21T15:02:02 Z | mhy908 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 115 ms | 4044 KB |
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define mp make_pair #define inf 987654321 using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; int n, m; int b[30010], p[30010]; int dijk[30010]; priority_queue<pii> pq; vector<int> jump[30010]; void dijkstra(int st) { pq.push({0, st}); dijk[st]=0; while(!pq.empty()){ pii y=pq.top(); int here=y.S, th=-y.F; pq.pop(); if(dijk[here]<th)continue; for(int i=0; i<jump[here].size(); i++){ for(int j=here-jump[here][i]; j>=0; j-=jump[here][i]){ if(dijk[j]>dijk[here]+(here-j)/jump[here][i]){ dijk[j]=dijk[here]+(here-j)/jump[here][i]; pq.push({-dijk[j], j}); } vector<int>::iterator it=lower_bound(jump[j].begin(), jump[j].end(), jump[here][i]); if(it!=jump[j].end()){ if(*it==jump[here][i])break; } } for(int j=here+jump[here][i]; j<n; j+=jump[here][i]){ if(dijk[j]>dijk[here]+(j-here)/jump[here][i]){ dijk[j]=dijk[here]+(j-here)/jump[here][i]; pq.push({-dijk[j], j}); } vector<int>::iterator it=lower_bound(jump[j].begin(), jump[j].end(), jump[here][i]); if(it!=jump[j].end()){ if(*it==jump[here][i])break; } } } } } int main() { scanf("%d %d", &n, &m); for(int i=1; i<=m; i++){ scanf("%d %d", &b[i], &p[i]); jump[b[i]].pb(p[i]); } for(int i=0; i<n; i++){ sort(jump[i].begin(), jump[i].end()); jump[i].erase(unique(jump[i].begin(), jump[i].end()), jump[i].end()); } fill(dijk, dijk+30005, inf); dijkstra(b[1]); printf("%d", dijk[b[2]]==inf?-1:dijk[b[2]]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
3 | Correct | 3 ms | 1144 KB | Output is correct |
4 | Correct | 3 ms | 1144 KB | Output is correct |
5 | Correct | 3 ms | 1144 KB | Output is correct |
6 | Correct | 3 ms | 1144 KB | Output is correct |
7 | Correct | 3 ms | 1144 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1148 KB | Output is correct |
3 | Correct | 3 ms | 1144 KB | Output is correct |
4 | Correct | 3 ms | 1144 KB | Output is correct |
5 | Correct | 3 ms | 1144 KB | Output is correct |
6 | Correct | 3 ms | 1144 KB | Output is correct |
7 | Correct | 3 ms | 1144 KB | Output is correct |
8 | Correct | 3 ms | 1144 KB | Output is correct |
9 | Correct | 3 ms | 1144 KB | Output is correct |
10 | Correct | 3 ms | 1144 KB | Output is correct |
11 | Correct | 3 ms | 1144 KB | Output is correct |
12 | Correct | 3 ms | 1144 KB | Output is correct |
13 | Correct | 3 ms | 1144 KB | Output is correct |
14 | Correct | 3 ms | 1144 KB | Output is correct |
15 | Correct | 3 ms | 1144 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
3 | Correct | 3 ms | 1144 KB | Output is correct |
4 | Correct | 3 ms | 1144 KB | Output is correct |
5 | Correct | 3 ms | 1144 KB | Output is correct |
6 | Correct | 3 ms | 1144 KB | Output is correct |
7 | Correct | 3 ms | 1144 KB | Output is correct |
8 | Correct | 3 ms | 1144 KB | Output is correct |
9 | Correct | 3 ms | 1144 KB | Output is correct |
10 | Correct | 3 ms | 1144 KB | Output is correct |
11 | Correct | 3 ms | 1144 KB | Output is correct |
12 | Correct | 3 ms | 1144 KB | Output is correct |
13 | Correct | 3 ms | 1144 KB | Output is correct |
14 | Correct | 3 ms | 1144 KB | Output is correct |
15 | Correct | 3 ms | 1144 KB | Output is correct |
16 | Correct | 3 ms | 1144 KB | Output is correct |
17 | Correct | 4 ms | 1244 KB | Output is correct |
18 | Correct | 3 ms | 1144 KB | Output is correct |
19 | Correct | 3 ms | 1144 KB | Output is correct |
20 | Correct | 3 ms | 1244 KB | Output is correct |
21 | Correct | 3 ms | 1144 KB | Output is correct |
22 | Correct | 3 ms | 1144 KB | Output is correct |
23 | Correct | 3 ms | 1144 KB | Output is correct |
24 | Correct | 4 ms | 1144 KB | Output is correct |
25 | Correct | 4 ms | 1272 KB | Output is correct |
26 | Correct | 3 ms | 1144 KB | Output is correct |
27 | Correct | 3 ms | 1144 KB | Output is correct |
28 | Correct | 4 ms | 1272 KB | Output is correct |
29 | Correct | 5 ms | 1276 KB | Output is correct |
30 | Correct | 4 ms | 1192 KB | Output is correct |
31 | Correct | 4 ms | 1272 KB | Output is correct |
32 | Correct | 3 ms | 1272 KB | Output is correct |
33 | Correct | 6 ms | 1400 KB | Output is correct |
34 | Correct | 6 ms | 1400 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
3 | Correct | 3 ms | 1148 KB | Output is correct |
4 | Correct | 1 ms | 1144 KB | Output is correct |
5 | Correct | 3 ms | 1144 KB | Output is correct |
6 | Correct | 3 ms | 1144 KB | Output is correct |
7 | Correct | 3 ms | 1144 KB | Output is correct |
8 | Correct | 3 ms | 1144 KB | Output is correct |
9 | Correct | 3 ms | 1148 KB | Output is correct |
10 | Correct | 3 ms | 1144 KB | Output is correct |
11 | Correct | 3 ms | 1148 KB | Output is correct |
12 | Correct | 3 ms | 1144 KB | Output is correct |
13 | Correct | 3 ms | 1144 KB | Output is correct |
14 | Correct | 3 ms | 1144 KB | Output is correct |
15 | Correct | 3 ms | 1144 KB | Output is correct |
16 | Correct | 3 ms | 1144 KB | Output is correct |
17 | Correct | 4 ms | 1144 KB | Output is correct |
18 | Correct | 4 ms | 1144 KB | Output is correct |
19 | Correct | 3 ms | 1144 KB | Output is correct |
20 | Correct | 3 ms | 1144 KB | Output is correct |
21 | Correct | 3 ms | 1144 KB | Output is correct |
22 | Correct | 3 ms | 1144 KB | Output is correct |
23 | Correct | 3 ms | 1144 KB | Output is correct |
24 | Correct | 4 ms | 1272 KB | Output is correct |
25 | Correct | 4 ms | 1272 KB | Output is correct |
26 | Correct | 3 ms | 1148 KB | Output is correct |
27 | Correct | 3 ms | 1144 KB | Output is correct |
28 | Correct | 4 ms | 1272 KB | Output is correct |
29 | Correct | 4 ms | 1276 KB | Output is correct |
30 | Correct | 4 ms | 1272 KB | Output is correct |
31 | Correct | 4 ms | 1272 KB | Output is correct |
32 | Correct | 4 ms | 1272 KB | Output is correct |
33 | Correct | 6 ms | 1400 KB | Output is correct |
34 | Correct | 6 ms | 1400 KB | Output is correct |
35 | Correct | 13 ms | 1528 KB | Output is correct |
36 | Correct | 5 ms | 1272 KB | Output is correct |
37 | Correct | 14 ms | 1528 KB | Output is correct |
38 | Correct | 17 ms | 1784 KB | Output is correct |
39 | Correct | 17 ms | 1788 KB | Output is correct |
40 | Correct | 17 ms | 1784 KB | Output is correct |
41 | Correct | 17 ms | 1656 KB | Output is correct |
42 | Correct | 9 ms | 1656 KB | Output is correct |
43 | Correct | 9 ms | 1576 KB | Output is correct |
44 | Correct | 9 ms | 1656 KB | Output is correct |
45 | Correct | 15 ms | 1784 KB | Output is correct |
46 | Correct | 16 ms | 1788 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
3 | Correct | 2 ms | 1144 KB | Output is correct |
4 | Correct | 3 ms | 1144 KB | Output is correct |
5 | Correct | 3 ms | 1144 KB | Output is correct |
6 | Correct | 3 ms | 1144 KB | Output is correct |
7 | Correct | 3 ms | 1144 KB | Output is correct |
8 | Correct | 3 ms | 1148 KB | Output is correct |
9 | Correct | 3 ms | 1144 KB | Output is correct |
10 | Correct | 3 ms | 1144 KB | Output is correct |
11 | Correct | 3 ms | 1144 KB | Output is correct |
12 | Correct | 3 ms | 1144 KB | Output is correct |
13 | Correct | 3 ms | 1144 KB | Output is correct |
14 | Correct | 3 ms | 1144 KB | Output is correct |
15 | Correct | 3 ms | 1144 KB | Output is correct |
16 | Correct | 3 ms | 1148 KB | Output is correct |
17 | Correct | 4 ms | 1272 KB | Output is correct |
18 | Correct | 3 ms | 1144 KB | Output is correct |
19 | Correct | 3 ms | 1144 KB | Output is correct |
20 | Correct | 3 ms | 1272 KB | Output is correct |
21 | Correct | 3 ms | 1144 KB | Output is correct |
22 | Correct | 3 ms | 1144 KB | Output is correct |
23 | Correct | 4 ms | 1144 KB | Output is correct |
24 | Correct | 4 ms | 1272 KB | Output is correct |
25 | Correct | 4 ms | 1272 KB | Output is correct |
26 | Correct | 3 ms | 1272 KB | Output is correct |
27 | Correct | 3 ms | 1144 KB | Output is correct |
28 | Correct | 3 ms | 1144 KB | Output is correct |
29 | Correct | 5 ms | 1272 KB | Output is correct |
30 | Correct | 4 ms | 1272 KB | Output is correct |
31 | Correct | 4 ms | 1272 KB | Output is correct |
32 | Correct | 4 ms | 1272 KB | Output is correct |
33 | Correct | 6 ms | 1400 KB | Output is correct |
34 | Correct | 6 ms | 1400 KB | Output is correct |
35 | Correct | 14 ms | 1656 KB | Output is correct |
36 | Correct | 5 ms | 1272 KB | Output is correct |
37 | Correct | 14 ms | 1656 KB | Output is correct |
38 | Correct | 19 ms | 1740 KB | Output is correct |
39 | Correct | 17 ms | 1656 KB | Output is correct |
40 | Correct | 17 ms | 1784 KB | Output is correct |
41 | Correct | 17 ms | 1656 KB | Output is correct |
42 | Correct | 9 ms | 1656 KB | Output is correct |
43 | Correct | 9 ms | 1656 KB | Output is correct |
44 | Correct | 9 ms | 1656 KB | Output is correct |
45 | Correct | 15 ms | 1812 KB | Output is correct |
46 | Correct | 15 ms | 1784 KB | Output is correct |
47 | Correct | 38 ms | 2296 KB | Output is correct |
48 | Correct | 11 ms | 1784 KB | Output is correct |
49 | Correct | 11 ms | 1784 KB | Output is correct |
50 | Correct | 9 ms | 1656 KB | Output is correct |
51 | Correct | 42 ms | 2556 KB | Output is correct |
52 | Correct | 41 ms | 2680 KB | Output is correct |
53 | Correct | 22 ms | 2680 KB | Output is correct |
54 | Correct | 4 ms | 1400 KB | Output is correct |
55 | Correct | 5 ms | 1400 KB | Output is correct |
56 | Correct | 15 ms | 2296 KB | Output is correct |
57 | Correct | 35 ms | 1908 KB | Output is correct |
58 | Correct | 14 ms | 1912 KB | Output is correct |
59 | Correct | 13 ms | 1912 KB | Output is correct |
60 | Correct | 13 ms | 1912 KB | Output is correct |
61 | Correct | 14 ms | 2040 KB | Output is correct |
62 | Correct | 23 ms | 2684 KB | Output is correct |
63 | Correct | 44 ms | 3060 KB | Output is correct |
64 | Correct | 47 ms | 2932 KB | Output is correct |
65 | Correct | 57 ms | 3060 KB | Output is correct |
66 | Correct | 115 ms | 3920 KB | Output is correct |
67 | Correct | 101 ms | 4044 KB | Output is correct |