답안 #566950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566950 2022-05-23T06:45:43 Z Sharky Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
770 ms 7928 KB
// trying c8kism be like
#include <bits/stdc++.h>
#define ef else if
#define pb push_back
#define leave exit(0);

using namespace std;

typedef int _;
typedef pair<_, _> _p;
typedef vector<_> v_;
typedef const long long constant;
constant maxn = 3E4 + 5;

_ n, m, c, b[maxn], p[maxn], dist[maxn];
set<_> dg[maxn];
void dijk(_ s);
int main() {

    scanf("%d %d", &n, &m);
    for (_ i = 0; i < m; ++i) scanf("%d %d", &b[i], &p[i]), dg[b[i]].insert(p[i]);
    if (b[0] == b[1]) puts("0"), leave
    dijk(b[0]);
    if (dist[b[1]] == 1E9) cout << "-1\n";
    else cout << dist[b[1]] << "\n";
    
    return 0;
}

void dijk(_ s) {
    priority_queue<_p, vector<_p>, greater<_p> > q;
    fill(dist, dist + maxn, 1E9);
    dist[s] = 0;
    q.push({0, s});
    while (!q.empty()) {
        _ d = q.top().first, u = q.top().second;
        q.pop();
        if (d != dist[u]) continue;
        for (_ jump : dg[u]) {
            c = 1;
            for (_ i = u + jump; i < n; i += jump, c++) {
                if (dist[i] > dist[u] + c) dist[i] = dist[u] + c, q.push({dist[i], i});
            }
            c = 1;
            for (_ i = u - jump; i >= 0; i -= jump, c++) {
                if (dist[i] > dist[u] + c) dist[i] = dist[u] + c, q.push({dist[i], i});
            } 
        }
    }
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:21:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     for (_ i = 0; i < m; ++i) scanf("%d %d", &b[i], &p[i]), dg[b[i]].insert(p[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Correct 2 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 2 ms 1748 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 1 ms 1748 KB Output is correct
7 Correct 2 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1620 KB Output is correct
4 Correct 2 ms 1748 KB Output is correct
5 Correct 2 ms 1840 KB Output is correct
6 Correct 1 ms 1748 KB Output is correct
7 Correct 1 ms 1836 KB Output is correct
8 Correct 2 ms 1840 KB Output is correct
9 Correct 2 ms 1836 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 3 ms 1852 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 2 ms 1964 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 2 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 1 ms 1840 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 2 ms 1748 KB Output is correct
7 Correct 1 ms 1836 KB Output is correct
8 Correct 1 ms 1836 KB Output is correct
9 Correct 2 ms 1816 KB Output is correct
10 Correct 1 ms 1840 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 2 ms 1852 KB Output is correct
14 Correct 2 ms 1940 KB Output is correct
15 Correct 2 ms 1852 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1844 KB Output is correct
20 Correct 7 ms 1876 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 2 ms 1876 KB Output is correct
25 Correct 3 ms 2004 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 2 ms 1852 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 2 ms 1876 KB Output is correct
32 Correct 2 ms 1964 KB Output is correct
33 Correct 5 ms 2260 KB Output is correct
34 Correct 6 ms 2232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1712 KB Output is correct
4 Correct 1 ms 1748 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 1 ms 1840 KB Output is correct
7 Correct 1 ms 1748 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 2 ms 1784 KB Output is correct
10 Correct 2 ms 1840 KB Output is correct
11 Correct 2 ms 1848 KB Output is correct
12 Correct 2 ms 1848 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 3 ms 1876 KB Output is correct
15 Correct 3 ms 1844 KB Output is correct
16 Correct 2 ms 1840 KB Output is correct
17 Correct 2 ms 1976 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 5 ms 1876 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 1 ms 1840 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 2 ms 1876 KB Output is correct
25 Correct 3 ms 1980 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1852 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 3 ms 2096 KB Output is correct
30 Correct 2 ms 1836 KB Output is correct
31 Correct 3 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 5 ms 2260 KB Output is correct
34 Correct 5 ms 2236 KB Output is correct
35 Correct 13 ms 3404 KB Output is correct
36 Correct 3 ms 2112 KB Output is correct
37 Correct 10 ms 3156 KB Output is correct
38 Correct 14 ms 3812 KB Output is correct
39 Correct 13 ms 3720 KB Output is correct
40 Correct 13 ms 3840 KB Output is correct
41 Correct 13 ms 3776 KB Output is correct
42 Correct 6 ms 2164 KB Output is correct
43 Correct 8 ms 2260 KB Output is correct
44 Correct 10 ms 2388 KB Output is correct
45 Correct 17 ms 4024 KB Output is correct
46 Correct 18 ms 4052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
3 Correct 1 ms 1708 KB Output is correct
4 Correct 1 ms 1844 KB Output is correct
5 Correct 1 ms 1748 KB Output is correct
6 Correct 1 ms 1748 KB Output is correct
7 Correct 1 ms 1748 KB Output is correct
8 Correct 1 ms 1748 KB Output is correct
9 Correct 1 ms 1748 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 2 ms 1848 KB Output is correct
20 Correct 6 ms 1968 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 2 ms 1848 KB Output is correct
24 Correct 3 ms 1944 KB Output is correct
25 Correct 3 ms 2004 KB Output is correct
26 Correct 3 ms 1876 KB Output is correct
27 Correct 3 ms 1848 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 3 ms 2028 KB Output is correct
30 Correct 3 ms 1876 KB Output is correct
31 Correct 2 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 4 ms 2260 KB Output is correct
34 Correct 5 ms 2260 KB Output is correct
35 Correct 13 ms 3416 KB Output is correct
36 Correct 3 ms 2108 KB Output is correct
37 Correct 9 ms 3156 KB Output is correct
38 Correct 15 ms 3768 KB Output is correct
39 Correct 15 ms 3828 KB Output is correct
40 Correct 15 ms 3788 KB Output is correct
41 Correct 14 ms 3796 KB Output is correct
42 Correct 7 ms 2260 KB Output is correct
43 Correct 7 ms 2260 KB Output is correct
44 Correct 10 ms 2392 KB Output is correct
45 Correct 15 ms 4052 KB Output is correct
46 Correct 16 ms 4052 KB Output is correct
47 Correct 19 ms 4060 KB Output is correct
48 Correct 10 ms 3272 KB Output is correct
49 Correct 9 ms 3172 KB Output is correct
50 Correct 6 ms 2744 KB Output is correct
51 Correct 32 ms 4944 KB Output is correct
52 Correct 25 ms 4436 KB Output is correct
53 Correct 18 ms 4476 KB Output is correct
54 Correct 3 ms 2004 KB Output is correct
55 Correct 3 ms 2004 KB Output is correct
56 Correct 770 ms 4052 KB Output is correct
57 Correct 41 ms 4084 KB Output is correct
58 Correct 10 ms 2388 KB Output is correct
59 Correct 9 ms 2460 KB Output is correct
60 Correct 14 ms 2524 KB Output is correct
61 Correct 10 ms 2652 KB Output is correct
62 Correct 13 ms 3692 KB Output is correct
63 Correct 40 ms 5836 KB Output is correct
64 Correct 45 ms 5836 KB Output is correct
65 Correct 46 ms 5792 KB Output is correct
66 Correct 99 ms 7852 KB Output is correct
67 Correct 113 ms 7928 KB Output is correct