Submission #1077830

# Submission time Handle Problem Language Result Execution time Memory
1077830 2024-08-27T09:28:26 Z dosts Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
30 ms 4820 KB
//DOST SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC optimise("O3,unroll-loops")
using namespace std;
#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:3: warning: ignoring '#pragma GCC optimise' [-Wunknown-pragmas]
    3 | #pragma GCC optimise("O3,unroll-loops")
      | 
skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:58:20: warning: 'tx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |     cout << (dis[tx] == LLONG_MAX ? -1 : dis[tx]);
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 0 ms 456 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 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 452 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 460 KB Output is correct
12 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 1 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 464 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 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 2 ms 560 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 468 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 604 KB Output is correct
29 Correct 1 ms 856 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory 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 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 464 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 1 ms 344 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 0 ms 348 KB Output is correct
31 Correct 0 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
35 Correct 10 ms 2004 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 14 ms 1752 KB Output is correct
38 Correct 16 ms 2396 KB Output is correct
39 Correct 13 ms 2396 KB Output is correct
40 Correct 14 ms 2396 KB Output is correct
41 Correct 13 ms 2140 KB Output is correct
42 Correct 3 ms 604 KB Output is correct
43 Correct 3 ms 600 KB Output is correct
44 Correct 3 ms 856 KB Output is correct
45 Correct 11 ms 2240 KB Output is correct
46 Correct 11 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 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 1 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 344 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 648 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 604 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 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 11 ms 1880 KB Output is correct
36 Correct 3 ms 728 KB Output is correct
37 Correct 17 ms 1628 KB Output is correct
38 Correct 14 ms 2396 KB Output is correct
39 Correct 14 ms 2396 KB Output is correct
40 Correct 14 ms 2396 KB Output is correct
41 Correct 14 ms 2136 KB Output is correct
42 Correct 6 ms 784 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 12 ms 2136 KB Output is correct
46 Correct 11 ms 2392 KB Output is correct
47 Correct 29 ms 3152 KB Output is correct
48 Correct 5 ms 2908 KB Output is correct
49 Correct 5 ms 2908 KB Output is correct
50 Correct 5 ms 2652 KB Output is correct
51 Correct 19 ms 4760 KB Output is correct
52 Correct 20 ms 4820 KB Output is correct
53 Correct 11 ms 4312 KB Output is correct
54 Correct 1 ms 1884 KB Output is correct
55 Correct 1 ms 1884 KB Output is correct
56 Correct 5 ms 3676 KB Output is correct
57 Correct 6 ms 2140 KB Output is correct
58 Correct 4 ms 2140 KB Output is correct
59 Correct 5 ms 2264 KB Output is correct
60 Correct 4 ms 2140 KB Output is correct
61 Correct 5 ms 2396 KB Output is correct
62 Correct 10 ms 3716 KB Output is correct
63 Correct 15 ms 3784 KB Output is correct
64 Correct 17 ms 3676 KB Output is correct
65 Correct 19 ms 3652 KB Output is correct
66 Correct 30 ms 3672 KB Output is correct
67 Correct 27 ms 3744 KB Output is correct