답안 #1038129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038129 2024-07-29T13:19:10 Z stdfloat Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
26 ms 4936 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int long long

#define ff  first
#define ss  second
#define pii pair<int, int>

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    int tx;
    vector<int> dis(n, LLONG_MAX);
    vector<set<int>> p(n);
    priority_queue<pii> q;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;

        p[x].insert(y);

        if (!i) {
            dis[x] = 0;
            q.push({0, x});
        }
        else if (i == 1) tx = x;
    }

    while (!q.empty()) {
        auto [d, x] = q.top(); d = -d; q.pop();

        if (d != dis[x]) continue;

        for (auto j : p[x]) {
            for (int i = x + j; i < n; i += j) {
                if (!p[i].empty() && d + abs(i - x) / j < dis[i]) {
                    dis[i] = d + abs(i - x) / j;
                    q.push({-dis[i], i});
                }

                if (p[i].find(j) != p[i].end()) break;
            }
            for (int i = x - j; i >= 0; i -= j) {
                if (!p[i].empty() && d + abs(i - x) / j < dis[i]) {
                    dis[i] = d + abs(i - x) / j;
                    q.push({-dis[i], i});
                }

                if (p[i].find(j) != p[i].end()) break;
            }
        }
    }

    cout << (dis[tx] == LLONG_MAX ? -1 : dis[tx]);
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:60:20: warning: 'tx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     cout << (dis[tx] == LLONG_MAX ? -1 : dis[tx]);
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 452 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 0 ms 468 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 11 ms 2068 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 10 ms 1628 KB Output is correct
38 Correct 14 ms 2396 KB Output is correct
39 Correct 14 ms 2372 KB Output is correct
40 Correct 15 ms 2396 KB Output is correct
41 Correct 16 ms 2140 KB Output is correct
42 Correct 4 ms 592 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 10 ms 2068 KB Output is correct
46 Correct 11 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 11 ms 2020 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 12 ms 1624 KB Output is correct
38 Correct 14 ms 2392 KB Output is correct
39 Correct 13 ms 2396 KB Output is correct
40 Correct 13 ms 2396 KB Output is correct
41 Correct 13 ms 2328 KB Output is correct
42 Correct 3 ms 604 KB Output is correct
43 Correct 3 ms 692 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 10 ms 2140 KB Output is correct
46 Correct 11 ms 2140 KB Output is correct
47 Correct 23 ms 3148 KB Output is correct
48 Correct 5 ms 2908 KB Output is correct
49 Correct 4 ms 2908 KB Output is correct
50 Correct 5 ms 2652 KB Output is correct
51 Correct 19 ms 4936 KB Output is correct
52 Correct 21 ms 4820 KB Output is correct
53 Correct 10 ms 4308 KB Output is correct
54 Correct 1 ms 1884 KB Output is correct
55 Correct 1 ms 1884 KB Output is correct
56 Correct 6 ms 3676 KB Output is correct
57 Correct 4 ms 2140 KB Output is correct
58 Correct 3 ms 2140 KB Output is correct
59 Correct 4 ms 2140 KB Output is correct
60 Correct 4 ms 2344 KB Output is correct
61 Correct 4 ms 2396 KB Output is correct
62 Correct 12 ms 3676 KB Output is correct
63 Correct 14 ms 3672 KB Output is correct
64 Correct 17 ms 3672 KB Output is correct
65 Correct 21 ms 3672 KB Output is correct
66 Correct 25 ms 3764 KB Output is correct
67 Correct 26 ms 3676 KB Output is correct