Submission #979765

# Submission time Handle Problem Language Result Execution time Memory
979765 2024-05-11T10:52:28 Z VMaksimoski008 Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 3548 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int maxn = 3e4 + 5;
vector<int> mp[maxn+1], B(maxn+1), P(maxn+1), dist(maxn+1, 1e9), vis(maxn+1);

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

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

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

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

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

        if(vis[u]) continue;
        vis[u] = 1;

        for(int &j : mp[u]) {
            int v = u + j;
            while(v <= n) {
                if(dist[v] > dist[u] + (v - u) / j) {
                    dist[v] = dist[u] + (v - u) / j;
                    pq.push({ dist[v], v });
                }
                v += j;
            }

            v = u - j;
            while(v >= 1) {
                if(dist[v] > dist[u] + (u - v) / j) {
                    dist[v] = dist[u] + (u - v) / j;
                    pq.push({ dist[v], v });
                }
                v -= j;
            }
        }
    }

    cout << (dist[B[1]] == 1e9 ? -1 : dist[B[1]]) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 2 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 3 ms 1628 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 2 ms 1428 KB Output is correct
15 Correct 2 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1368 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 3 ms 1628 KB Output is correct
13 Correct 2 ms 1628 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 2 ms 1628 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 1 ms 1628 KB Output is correct
20 Correct 24 ms 1628 KB Output is correct
21 Correct 1 ms 1628 KB Output is correct
22 Correct 1 ms 1624 KB Output is correct
23 Correct 1 ms 1880 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 2 ms 1628 KB Output is correct
26 Correct 22 ms 1628 KB Output is correct
27 Correct 21 ms 1628 KB Output is correct
28 Correct 2 ms 1628 KB Output is correct
29 Correct 2 ms 1628 KB Output is correct
30 Correct 2 ms 1628 KB Output is correct
31 Correct 2 ms 1628 KB Output is correct
32 Correct 2 ms 1628 KB Output is correct
33 Correct 3 ms 1628 KB Output is correct
34 Correct 3 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1368 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 2 ms 1628 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 3 ms 1628 KB Output is correct
14 Correct 2 ms 1628 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 1 ms 1628 KB Output is correct
20 Correct 24 ms 1720 KB Output is correct
21 Correct 1 ms 1628 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 2 ms 1628 KB Output is correct
26 Correct 22 ms 1628 KB Output is correct
27 Correct 21 ms 1656 KB Output is correct
28 Correct 2 ms 1628 KB Output is correct
29 Correct 2 ms 1628 KB Output is correct
30 Correct 1 ms 1628 KB Output is correct
31 Correct 2 ms 1612 KB Output is correct
32 Correct 1 ms 1628 KB Output is correct
33 Correct 3 ms 1628 KB Output is correct
34 Correct 3 ms 1628 KB Output is correct
35 Correct 11 ms 1884 KB Output is correct
36 Correct 3 ms 1628 KB Output is correct
37 Correct 9 ms 2016 KB Output is correct
38 Correct 13 ms 2208 KB Output is correct
39 Correct 15 ms 2140 KB Output is correct
40 Correct 14 ms 2140 KB Output is correct
41 Correct 13 ms 2140 KB Output is correct
42 Correct 347 ms 2036 KB Output is correct
43 Correct 340 ms 2012 KB Output is correct
44 Correct 353 ms 1884 KB Output is correct
45 Correct 13 ms 2140 KB Output is correct
46 Correct 13 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 2 ms 1628 KB Output is correct
13 Correct 2 ms 1640 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 2 ms 1628 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 1 ms 1628 KB Output is correct
19 Correct 1 ms 1628 KB Output is correct
20 Correct 24 ms 1628 KB Output is correct
21 Correct 2 ms 1628 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 2 ms 1628 KB Output is correct
26 Correct 22 ms 1628 KB Output is correct
27 Correct 20 ms 1628 KB Output is correct
28 Correct 2 ms 1628 KB Output is correct
29 Correct 3 ms 1628 KB Output is correct
30 Correct 1 ms 1628 KB Output is correct
31 Correct 2 ms 1628 KB Output is correct
32 Correct 2 ms 1628 KB Output is correct
33 Correct 3 ms 1628 KB Output is correct
34 Correct 3 ms 1784 KB Output is correct
35 Correct 11 ms 2100 KB Output is correct
36 Correct 3 ms 1628 KB Output is correct
37 Correct 9 ms 1884 KB Output is correct
38 Correct 13 ms 2032 KB Output is correct
39 Correct 13 ms 2140 KB Output is correct
40 Correct 13 ms 2032 KB Output is correct
41 Correct 17 ms 2140 KB Output is correct
42 Correct 348 ms 1884 KB Output is correct
43 Correct 340 ms 1992 KB Output is correct
44 Correct 351 ms 1936 KB Output is correct
45 Correct 13 ms 2140 KB Output is correct
46 Correct 13 ms 2140 KB Output is correct
47 Correct 22 ms 2780 KB Output is correct
48 Correct 10 ms 2140 KB Output is correct
49 Correct 10 ms 2140 KB Output is correct
50 Correct 7 ms 1884 KB Output is correct
51 Correct 28 ms 3548 KB Output is correct
52 Correct 27 ms 3036 KB Output is correct
53 Correct 19 ms 3036 KB Output is correct
54 Correct 2 ms 1628 KB Output is correct
55 Correct 2 ms 1628 KB Output is correct
56 Execution timed out 1090 ms 3164 KB Time limit exceeded
57 Halted 0 ms 0 KB -