Submission #957501

# Submission time Handle Problem Language Result Execution time Memory
957501 2024-04-03T22:01:15 Z aykhn Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
132 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define inf 0x3F3F3F3F3F3F3F3F

const int MXN = 3e4 + 5;

int b[MXN], p[MXN], dist[MXN];
vector<int> adj[MXN];
vector<int> mp[MXN];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) mp[i].assign(i + 1, 0);
    for (int i = 0; i < n; i++) dist[i] = inf;
    for (int i = 0; i < m; i++)
    {
        cin >> b[i] >> p[i];
        if (p[i] > n) continue;
        adj[b[i]].push_back(p[i]);
    }
    priority_queue<array<int, 2>, vector<array<int, 2>>, greater<array<int, 2>>> pq;
    dist[b[0]] = 0;
    pq.push({0, b[0]});
    while (!pq.empty())
    {
        array<int, 2> f = pq.top();
        pq.pop();
        if (f[0] > dist[f[1]]) continue;
        for (int v : adj[f[1]])
        {
            if (mp[v][f[1] % v]) continue;
            mp[v][f[1] % v] = 1;
            for (int i = f[1] - v; i >= 0; i -= v)
            {
                if (dist[i] > dist[f[1]] + ((f[1] - i) / v))
                {
                    dist[i] = dist[f[1]] + ((f[1] - i) / v);
                    pq.push({dist[i], i});
                }
            }
            for (int i = f[1] + v; i < n; i += v)
            {
                if (dist[i] > dist[f[1]] + ((i - f[1]) / v))
                {
                    dist[i] = dist[f[1]] + ((i - f[1]) / v);
                    pq.push({dist[i], i});
                }
            }
        }
    }
    cout << (dist[b[1]] >= inf ? -1 : dist[b[1]]) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1624 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1668 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 1 ms 1880 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1880 KB Output is correct
16 Correct 1 ms 1880 KB Output is correct
17 Correct 3 ms 3932 KB Output is correct
18 Correct 8 ms 13916 KB Output is correct
19 Correct 7 ms 17500 KB Output is correct
20 Correct 7 ms 17752 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 6 ms 14172 KB Output is correct
23 Correct 5 ms 11868 KB Output is correct
24 Correct 7 ms 15964 KB Output is correct
25 Correct 8 ms 17756 KB Output is correct
26 Correct 7 ms 17500 KB Output is correct
27 Correct 7 ms 17500 KB Output is correct
28 Correct 8 ms 17496 KB Output is correct
29 Correct 9 ms 18012 KB Output is correct
30 Correct 8 ms 17756 KB Output is correct
31 Correct 9 ms 17752 KB Output is correct
32 Correct 8 ms 17756 KB Output is correct
33 Correct 9 ms 18008 KB Output is correct
34 Correct 9 ms 18012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1624 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1880 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1880 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1880 KB Output is correct
17 Correct 2 ms 3932 KB Output is correct
18 Correct 6 ms 13916 KB Output is correct
19 Correct 7 ms 17500 KB Output is correct
20 Correct 8 ms 17756 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 6 ms 14172 KB Output is correct
23 Correct 5 ms 11868 KB Output is correct
24 Correct 8 ms 15960 KB Output is correct
25 Correct 10 ms 17756 KB Output is correct
26 Correct 8 ms 17496 KB Output is correct
27 Correct 7 ms 17496 KB Output is correct
28 Correct 7 ms 17500 KB Output is correct
29 Correct 9 ms 18008 KB Output is correct
30 Correct 10 ms 17756 KB Output is correct
31 Correct 8 ms 17752 KB Output is correct
32 Correct 8 ms 17756 KB Output is correct
33 Correct 9 ms 17940 KB Output is correct
34 Correct 10 ms 18012 KB Output is correct
35 Correct 9 ms 10588 KB Output is correct
36 Correct 4 ms 6492 KB Output is correct
37 Correct 12 ms 17244 KB Output is correct
38 Correct 13 ms 18524 KB Output is correct
39 Correct 13 ms 18520 KB Output is correct
40 Correct 13 ms 18524 KB Output is correct
41 Correct 14 ms 18524 KB Output is correct
42 Correct 11 ms 18392 KB Output is correct
43 Correct 13 ms 18392 KB Output is correct
44 Correct 11 ms 18388 KB Output is correct
45 Correct 15 ms 18776 KB Output is correct
46 Correct 17 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1624 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1624 KB Output is correct
6 Correct 2 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 2 ms 3932 KB Output is correct
18 Correct 6 ms 13916 KB Output is correct
19 Correct 7 ms 17500 KB Output is correct
20 Correct 8 ms 17756 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 6 ms 14180 KB Output is correct
23 Correct 5 ms 11864 KB Output is correct
24 Correct 8 ms 15964 KB Output is correct
25 Correct 8 ms 17752 KB Output is correct
26 Correct 8 ms 17500 KB Output is correct
27 Correct 8 ms 17500 KB Output is correct
28 Correct 8 ms 17500 KB Output is correct
29 Correct 9 ms 18012 KB Output is correct
30 Correct 7 ms 17756 KB Output is correct
31 Correct 9 ms 17756 KB Output is correct
32 Correct 9 ms 17756 KB Output is correct
33 Correct 10 ms 17956 KB Output is correct
34 Correct 10 ms 17924 KB Output is correct
35 Correct 9 ms 10560 KB Output is correct
36 Correct 4 ms 6744 KB Output is correct
37 Correct 14 ms 17248 KB Output is correct
38 Correct 14 ms 18524 KB Output is correct
39 Correct 14 ms 18524 KB Output is correct
40 Correct 15 ms 18524 KB Output is correct
41 Correct 14 ms 18524 KB Output is correct
42 Correct 10 ms 18392 KB Output is correct
43 Correct 10 ms 18392 KB Output is correct
44 Correct 11 ms 18396 KB Output is correct
45 Correct 14 ms 18780 KB Output is correct
46 Correct 14 ms 18780 KB Output is correct
47 Runtime error 132 ms 262144 KB Execution killed with signal 9
48 Halted 0 ms 0 KB -