# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
99463 | 2019-03-04T08:11:27 Z | Shafin666 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 379 ms | 68744 KB |
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pii pair<int, int> typedef long long ll; typedef long double ld; using namespace std; vector<int> adj[30005], cost[30005]; set<int> s[30005]; int b[30005], dist[30005]; int main() { int n, m; int i, j, k; int x, y; cin >> n >> m; for(int i = 0; i < m; i++) { cin >> x >> y; b[i] = x; s[x].insert(y); } for(int pos = 0; pos < n; pos++) { dist[pos] = 1e9+7; for(int p : s[pos]) { for(int i = 1; ; i++) { if(pos + i*p < n) { adj[pos].pb(pos + i*p); cost[pos].pb(i); if(s[pos + i*p].find(p) != s[pos + i*p].end()) break; } else break; } for(int i = 1; ; i++) { if(pos - i*p >= 0) { adj[pos].pb(pos - i*p); cost[pos].pb(i); if(s[pos - i*p].find(p) != s[pos - i*p].end()) break; } else break; } } } priority_queue<pii, vector<pii>, greater<pii>> pq; dist[b[0]] = 0; pq.push({dist[b[0]], b[0]}); while(!pq.empty()) { pii p = pq.top(); pq.pop(); int u = p.second; int w = p.first; for(int i = 0; i < (int) adj[u].size(); i++) { int c = cost[u][i]; int v = adj[u][i]; if(dist[v] > w+c) { dist[v] = w+c; pq.push({dist[v], v}); } } } if(dist[b[1]] >= 1e8) cout << -1 << endl; else cout << dist[b[1]] << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3200 KB | Output is correct |
2 | Correct | 5 ms | 3200 KB | Output is correct |
3 | Correct | 5 ms | 3200 KB | Output is correct |
4 | Correct | 4 ms | 3072 KB | Output is correct |
5 | Correct | 4 ms | 3072 KB | Output is correct |
6 | Correct | 5 ms | 3200 KB | Output is correct |
7 | Correct | 2 ms | 3200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3200 KB | Output is correct |
2 | Correct | 4 ms | 3200 KB | Output is correct |
3 | Correct | 5 ms | 3072 KB | Output is correct |
4 | Correct | 4 ms | 3200 KB | Output is correct |
5 | Correct | 5 ms | 3200 KB | Output is correct |
6 | Correct | 5 ms | 3200 KB | Output is correct |
7 | Correct | 5 ms | 3072 KB | Output is correct |
8 | Correct | 5 ms | 3200 KB | Output is correct |
9 | Correct | 6 ms | 3200 KB | Output is correct |
10 | Correct | 5 ms | 3200 KB | Output is correct |
11 | Correct | 9 ms | 3328 KB | Output is correct |
12 | Correct | 6 ms | 3200 KB | Output is correct |
13 | Correct | 6 ms | 3200 KB | Output is correct |
14 | Correct | 6 ms | 3328 KB | Output is correct |
15 | Correct | 8 ms | 3328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3072 KB | Output is correct |
2 | Correct | 3 ms | 3072 KB | Output is correct |
3 | Correct | 5 ms | 3072 KB | Output is correct |
4 | Correct | 5 ms | 3072 KB | Output is correct |
5 | Correct | 5 ms | 3200 KB | Output is correct |
6 | Correct | 4 ms | 3200 KB | Output is correct |
7 | Correct | 4 ms | 3200 KB | Output is correct |
8 | Correct | 4 ms | 3072 KB | Output is correct |
9 | Correct | 5 ms | 3200 KB | Output is correct |
10 | Correct | 6 ms | 3200 KB | Output is correct |
11 | Correct | 8 ms | 3328 KB | Output is correct |
12 | Correct | 5 ms | 3200 KB | Output is correct |
13 | Correct | 6 ms | 3200 KB | Output is correct |
14 | Correct | 6 ms | 3328 KB | Output is correct |
15 | Correct | 6 ms | 3328 KB | Output is correct |
16 | Correct | 5 ms | 3200 KB | Output is correct |
17 | Correct | 7 ms | 3456 KB | Output is correct |
18 | Correct | 6 ms | 3328 KB | Output is correct |
19 | Correct | 6 ms | 3200 KB | Output is correct |
20 | Correct | 8 ms | 3456 KB | Output is correct |
21 | Correct | 7 ms | 3200 KB | Output is correct |
22 | Correct | 5 ms | 3200 KB | Output is correct |
23 | Correct | 6 ms | 3328 KB | Output is correct |
24 | Correct | 8 ms | 3456 KB | Output is correct |
25 | Correct | 8 ms | 3456 KB | Output is correct |
26 | Correct | 6 ms | 3328 KB | Output is correct |
27 | Correct | 6 ms | 3328 KB | Output is correct |
28 | Correct | 9 ms | 3456 KB | Output is correct |
29 | Correct | 10 ms | 4096 KB | Output is correct |
30 | Correct | 3 ms | 3456 KB | Output is correct |
31 | Correct | 7 ms | 3584 KB | Output is correct |
32 | Correct | 6 ms | 3456 KB | Output is correct |
33 | Correct | 12 ms | 4864 KB | Output is correct |
34 | Correct | 12 ms | 4864 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3200 KB | Output is correct |
2 | Correct | 4 ms | 3072 KB | Output is correct |
3 | Correct | 4 ms | 3200 KB | Output is correct |
4 | Correct | 4 ms | 3072 KB | Output is correct |
5 | Correct | 4 ms | 3072 KB | Output is correct |
6 | Correct | 6 ms | 3072 KB | Output is correct |
7 | Correct | 5 ms | 3200 KB | Output is correct |
8 | Correct | 4 ms | 3072 KB | Output is correct |
9 | Correct | 5 ms | 3200 KB | Output is correct |
10 | Correct | 5 ms | 3200 KB | Output is correct |
11 | Correct | 7 ms | 3328 KB | Output is correct |
12 | Correct | 6 ms | 3200 KB | Output is correct |
13 | Correct | 6 ms | 3200 KB | Output is correct |
14 | Correct | 6 ms | 3328 KB | Output is correct |
15 | Correct | 6 ms | 3328 KB | Output is correct |
16 | Correct | 7 ms | 3200 KB | Output is correct |
17 | Correct | 10 ms | 3456 KB | Output is correct |
18 | Correct | 6 ms | 3328 KB | Output is correct |
19 | Correct | 6 ms | 3200 KB | Output is correct |
20 | Correct | 7 ms | 3456 KB | Output is correct |
21 | Correct | 7 ms | 3328 KB | Output is correct |
22 | Correct | 6 ms | 3328 KB | Output is correct |
23 | Correct | 8 ms | 3328 KB | Output is correct |
24 | Correct | 9 ms | 3456 KB | Output is correct |
25 | Correct | 8 ms | 3448 KB | Output is correct |
26 | Correct | 7 ms | 3328 KB | Output is correct |
27 | Correct | 8 ms | 3328 KB | Output is correct |
28 | Correct | 7 ms | 3456 KB | Output is correct |
29 | Correct | 9 ms | 4096 KB | Output is correct |
30 | Correct | 7 ms | 3456 KB | Output is correct |
31 | Correct | 8 ms | 3712 KB | Output is correct |
32 | Correct | 6 ms | 3556 KB | Output is correct |
33 | Correct | 11 ms | 4864 KB | Output is correct |
34 | Correct | 11 ms | 4864 KB | Output is correct |
35 | Correct | 40 ms | 5692 KB | Output is correct |
36 | Correct | 10 ms | 3584 KB | Output is correct |
37 | Correct | 41 ms | 6392 KB | Output is correct |
38 | Correct | 57 ms | 6776 KB | Output is correct |
39 | Correct | 54 ms | 6776 KB | Output is correct |
40 | Correct | 72 ms | 6776 KB | Output is correct |
41 | Correct | 68 ms | 6776 KB | Output is correct |
42 | Correct | 19 ms | 3584 KB | Output is correct |
43 | Correct | 23 ms | 3584 KB | Output is correct |
44 | Correct | 25 ms | 3704 KB | Output is correct |
45 | Correct | 57 ms | 9720 KB | Output is correct |
46 | Correct | 77 ms | 9724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3200 KB | Output is correct |
2 | Correct | 5 ms | 3200 KB | Output is correct |
3 | Correct | 5 ms | 3072 KB | Output is correct |
4 | Correct | 5 ms | 3200 KB | Output is correct |
5 | Correct | 5 ms | 3200 KB | Output is correct |
6 | Correct | 4 ms | 3200 KB | Output is correct |
7 | Correct | 5 ms | 3200 KB | Output is correct |
8 | Correct | 5 ms | 3328 KB | Output is correct |
9 | Correct | 5 ms | 3200 KB | Output is correct |
10 | Correct | 6 ms | 3200 KB | Output is correct |
11 | Correct | 6 ms | 3328 KB | Output is correct |
12 | Correct | 5 ms | 3072 KB | Output is correct |
13 | Correct | 6 ms | 3200 KB | Output is correct |
14 | Correct | 6 ms | 3328 KB | Output is correct |
15 | Correct | 6 ms | 3328 KB | Output is correct |
16 | Correct | 5 ms | 3200 KB | Output is correct |
17 | Correct | 7 ms | 3456 KB | Output is correct |
18 | Correct | 7 ms | 3328 KB | Output is correct |
19 | Correct | 5 ms | 3200 KB | Output is correct |
20 | Correct | 7 ms | 3328 KB | Output is correct |
21 | Correct | 5 ms | 3200 KB | Output is correct |
22 | Correct | 5 ms | 3200 KB | Output is correct |
23 | Correct | 8 ms | 3328 KB | Output is correct |
24 | Correct | 10 ms | 3456 KB | Output is correct |
25 | Correct | 8 ms | 3456 KB | Output is correct |
26 | Correct | 7 ms | 3328 KB | Output is correct |
27 | Correct | 7 ms | 3200 KB | Output is correct |
28 | Correct | 8 ms | 3584 KB | Output is correct |
29 | Correct | 9 ms | 4096 KB | Output is correct |
30 | Correct | 6 ms | 3456 KB | Output is correct |
31 | Correct | 6 ms | 3712 KB | Output is correct |
32 | Correct | 6 ms | 3584 KB | Output is correct |
33 | Correct | 12 ms | 4864 KB | Output is correct |
34 | Correct | 14 ms | 4864 KB | Output is correct |
35 | Correct | 42 ms | 5756 KB | Output is correct |
36 | Correct | 11 ms | 3584 KB | Output is correct |
37 | Correct | 37 ms | 6424 KB | Output is correct |
38 | Correct | 48 ms | 6732 KB | Output is correct |
39 | Correct | 49 ms | 6748 KB | Output is correct |
40 | Correct | 52 ms | 6776 KB | Output is correct |
41 | Correct | 49 ms | 6648 KB | Output is correct |
42 | Correct | 33 ms | 3576 KB | Output is correct |
43 | Correct | 26 ms | 3580 KB | Output is correct |
44 | Correct | 30 ms | 3704 KB | Output is correct |
45 | Correct | 66 ms | 9728 KB | Output is correct |
46 | Correct | 74 ms | 9740 KB | Output is correct |
47 | Correct | 90 ms | 14196 KB | Output is correct |
48 | Correct | 42 ms | 7416 KB | Output is correct |
49 | Correct | 49 ms | 6264 KB | Output is correct |
50 | Correct | 37 ms | 5888 KB | Output is correct |
51 | Correct | 88 ms | 9472 KB | Output is correct |
52 | Correct | 89 ms | 9992 KB | Output is correct |
53 | Correct | 48 ms | 6772 KB | Output is correct |
54 | Correct | 8 ms | 3712 KB | Output is correct |
55 | Correct | 8 ms | 4352 KB | Output is correct |
56 | Correct | 53 ms | 6904 KB | Output is correct |
57 | Correct | 60 ms | 12408 KB | Output is correct |
58 | Correct | 19 ms | 4600 KB | Output is correct |
59 | Correct | 25 ms | 5084 KB | Output is correct |
60 | Correct | 31 ms | 5752 KB | Output is correct |
61 | Correct | 44 ms | 5112 KB | Output is correct |
62 | Correct | 63 ms | 10744 KB | Output is correct |
63 | Correct | 117 ms | 28780 KB | Output is correct |
64 | Correct | 132 ms | 31856 KB | Output is correct |
65 | Correct | 184 ms | 41504 KB | Output is correct |
66 | Correct | 379 ms | 68744 KB | Output is correct |
67 | Correct | 360 ms | 68612 KB | Output is correct |