Submission #979786

# Submission time Handle Problem Language Result Execution time Memory
979786 2024-05-11T11:06:58 Z VMaksimoski008 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
88 ms 6616 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int M = 3e4 + 5;
vector<int> mp[M+1], B(M+1), P(M+1), D(M+1, 1e9);
set<int> S[M+1];

int main() {
    int n, m;
    cin >> n >> m;

    for(int i=0; i<m; i++) {
        cin >> B[i] >> P[i];
        if(!S[++B[i]].count(P[i])) mp[B[i]].push_back(P[i]);
        S[B[i]].insert(P[i]);
    }

    priority_queue<pii, vector<pii>, greater<pii> > pq;

    D[B[0]] = 0;
    pq.push({ 0, B[0] });

    while(!pq.empty()) {
        auto [d, u] = pq.top();
        pq.pop();

        if(d != D[u]) continue;
       
        for(int &j : mp[u]) {
            int v = u + j;
            while(v <= n) {
                if(D[v] > d + (v - u) / j) {
                    D[v] = d + (v - u) / j;
                    pq.push({ D[v], v });
                }
                if(S[v].count(j)) break;
                v += j;
            }

            v = u - j;
            while(v >= 1) {
                if(D[v] > d + (u - v) / j) {
                    D[v] = d + (u - v) / j;
                    pq.push({ D[v], v });
                }
                if(S[v].count(j)) break;
                v -= j;
            }
        }
    }

    cout << (D[B[1]] == 1e9 ? -1 : D[B[1]]) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 2 ms 2908 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2904 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2908 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2904 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 2904 KB Output is correct
11 Correct 3 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 2 ms 2904 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 2 ms 2908 KB Output is correct
24 Correct 3 ms 2908 KB Output is correct
25 Correct 3 ms 2908 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 3 ms 2960 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 4 ms 3164 KB Output is correct
34 Correct 4 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2904 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2920 KB Output is correct
17 Correct 3 ms 2908 KB Output is correct
18 Correct 2 ms 2820 KB Output is correct
19 Correct 1 ms 2904 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 3 ms 2908 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 3 ms 2908 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 3 ms 2908 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 3 ms 2908 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 4 ms 3164 KB Output is correct
34 Correct 5 ms 3164 KB Output is correct
35 Correct 17 ms 4376 KB Output is correct
36 Correct 4 ms 3164 KB Output is correct
37 Correct 16 ms 4028 KB Output is correct
38 Correct 22 ms 4444 KB Output is correct
39 Correct 22 ms 4444 KB Output is correct
40 Correct 22 ms 4444 KB Output is correct
41 Correct 21 ms 4440 KB Output is correct
42 Correct 10 ms 2908 KB Output is correct
43 Correct 11 ms 2916 KB Output is correct
44 Correct 11 ms 2904 KB Output is correct
45 Correct 19 ms 4440 KB Output is correct
46 Correct 20 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2840 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 3160 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2904 KB Output is correct
17 Correct 3 ms 2908 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 2904 KB Output is correct
23 Correct 2 ms 2908 KB Output is correct
24 Correct 3 ms 2924 KB Output is correct
25 Correct 3 ms 2908 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 3 ms 2904 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 2904 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 4 ms 3164 KB Output is correct
34 Correct 4 ms 3164 KB Output is correct
35 Correct 17 ms 4188 KB Output is correct
36 Correct 4 ms 3164 KB Output is correct
37 Correct 21 ms 3936 KB Output is correct
38 Correct 22 ms 4444 KB Output is correct
39 Correct 22 ms 4600 KB Output is correct
40 Correct 22 ms 4444 KB Output is correct
41 Correct 22 ms 4644 KB Output is correct
42 Correct 11 ms 2908 KB Output is correct
43 Correct 11 ms 2908 KB Output is correct
44 Correct 12 ms 2904 KB Output is correct
45 Correct 20 ms 4584 KB Output is correct
46 Correct 20 ms 4440 KB Output is correct
47 Correct 32 ms 4832 KB Output is correct
48 Correct 13 ms 4188 KB Output is correct
49 Correct 12 ms 4188 KB Output is correct
50 Correct 9 ms 3932 KB Output is correct
51 Correct 34 ms 5332 KB Output is correct
52 Correct 40 ms 5452 KB Output is correct
53 Correct 23 ms 5344 KB Output is correct
54 Correct 2 ms 2908 KB Output is correct
55 Correct 3 ms 2908 KB Output is correct
56 Correct 17 ms 5160 KB Output is correct
57 Correct 22 ms 3612 KB Output is correct
58 Correct 11 ms 2908 KB Output is correct
59 Correct 13 ms 2900 KB Output is correct
60 Correct 17 ms 3172 KB Output is correct
61 Correct 16 ms 3164 KB Output is correct
62 Correct 20 ms 5212 KB Output is correct
63 Correct 47 ms 5600 KB Output is correct
64 Correct 48 ms 5592 KB Output is correct
65 Correct 59 ms 6616 KB Output is correct
66 Correct 87 ms 6608 KB Output is correct
67 Correct 88 ms 6424 KB Output is correct