Submission #870359

# Submission time Handle Problem Language Result Execution time Memory
870359 2023-11-07T13:32:29 Z Namviet2704 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
122 ms 8992 KB
#include <bits/stdc++.h>

using namespace std;

const int sqr = 205;
const int N = 4e4 + 2;

struct node
{
    int v, p, w;
    node(int v, int p, int w) : v(v), p(p), w(w) {}
};

int dis[N];
bool vs[N][sqr + 10];
vector<int> adj[N];
queue<node> q;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int s, t, n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int v, p;
        cin >> v >> p;
        adj[v].push_back(p);
        if (i == 0)
            s = v;
        if (i == 1)
            t = v;
    }
    memset(dis, -1, sizeof(dis));
    q.emplace(s, 0, 0);
    while (!q.empty())
    {
        node h = q.front();
        q.pop();
        if (h.v < 0 || h.v >= n)
            continue;
        if (abs(h.p) < sqr)
        { // neu p < can thi chi duyet qua 1 lan
            if (vs[h.v][abs(h.p)])
                continue;
            vs[h.v][abs(h.p)] = 1;
        }
        if (dis[h.v] == -1)
        {
            dis[h.v] = h.w;
            for (int p : adj[h.v])
            {
                q.emplace(h.v + p, p, h.w + 1);  // di theo buoc nhay p ve huong ben phai
                q.emplace(h.v - p, -p, h.w + 1); // di theo buoc nhay p ve huong ben trai
            }
        }
        q.emplace(h.v + h.p, h.p, h.w + 1); // tiep tuc di theo buoc nhay
    }
    cout << dis[t];
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:11:48: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   11 |     node(int v, int p, int w) : v(v), p(p), w(w) {}
      |                                                ^
skyscraper.cpp:23:9: note: 's' was declared here
   23 |     int s, t, n, m;
      |         ^
skyscraper.cpp:60:18: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     cout << dis[t];
      |                  ^
# 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 2684 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2688 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2692 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2696 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2700 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2688 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2688 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2696 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2700 KB Output is correct
13 Correct 1 ms 2696 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2904 KB Output is correct
24 Correct 1 ms 2908 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2704 KB Output is correct
27 Correct 1 ms 2904 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2908 KB Output is correct
34 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 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 2660 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2904 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 1 ms 2704 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2696 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2908 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2708 KB Output is correct
27 Correct 1 ms 2708 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 1 ms 2700 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 2 ms 2908 KB Output is correct
34 Correct 2 ms 2908 KB Output is correct
35 Correct 6 ms 3676 KB Output is correct
36 Correct 2 ms 2908 KB Output is correct
37 Correct 6 ms 3552 KB Output is correct
38 Correct 7 ms 3928 KB Output is correct
39 Correct 7 ms 3932 KB Output is correct
40 Correct 7 ms 3932 KB Output is correct
41 Correct 7 ms 3956 KB Output is correct
42 Correct 6 ms 3676 KB Output is correct
43 Correct 4 ms 3716 KB Output is correct
44 Correct 4 ms 3676 KB Output is correct
45 Correct 8 ms 3932 KB Output is correct
46 Correct 9 ms 3784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 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 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2688 KB Output is correct
11 Correct 1 ms 2904 KB Output is correct
12 Correct 1 ms 2904 KB Output is correct
13 Correct 2 ms 2852 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2704 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2696 KB Output is correct
20 Correct 1 ms 2904 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2916 KB Output is correct
25 Correct 1 ms 2916 KB Output is correct
26 Correct 1 ms 2916 KB Output is correct
27 Correct 1 ms 2916 KB Output is correct
28 Correct 1 ms 2712 KB Output is correct
29 Correct 1 ms 2660 KB Output is correct
30 Correct 1 ms 2696 KB Output is correct
31 Correct 1 ms 2660 KB Output is correct
32 Correct 1 ms 2660 KB Output is correct
33 Correct 2 ms 2920 KB Output is correct
34 Correct 2 ms 2920 KB Output is correct
35 Correct 9 ms 3676 KB Output is correct
36 Correct 2 ms 2956 KB Output is correct
37 Correct 5 ms 3420 KB Output is correct
38 Correct 7 ms 3932 KB Output is correct
39 Correct 7 ms 3932 KB Output is correct
40 Correct 7 ms 3932 KB Output is correct
41 Correct 7 ms 3932 KB Output is correct
42 Correct 5 ms 3676 KB Output is correct
43 Correct 4 ms 3676 KB Output is correct
44 Correct 4 ms 3868 KB Output is correct
45 Correct 8 ms 3988 KB Output is correct
46 Correct 9 ms 3984 KB Output is correct
47 Correct 21 ms 5212 KB Output is correct
48 Correct 5 ms 3416 KB Output is correct
49 Correct 6 ms 3420 KB Output is correct
50 Correct 5 ms 3164 KB Output is correct
51 Correct 16 ms 8740 KB Output is correct
52 Correct 15 ms 8796 KB Output is correct
53 Correct 14 ms 8720 KB Output is correct
54 Correct 3 ms 7772 KB Output is correct
55 Correct 3 ms 8024 KB Output is correct
56 Correct 11 ms 8796 KB Output is correct
57 Correct 8 ms 7772 KB Output is correct
58 Correct 10 ms 8792 KB Output is correct
59 Correct 14 ms 8936 KB Output is correct
60 Correct 9 ms 8796 KB Output is correct
61 Correct 11 ms 8796 KB Output is correct
62 Correct 17 ms 8992 KB Output is correct
63 Correct 26 ms 8388 KB Output is correct
64 Correct 33 ms 8512 KB Output is correct
65 Correct 64 ms 8608 KB Output is correct
66 Correct 91 ms 8988 KB Output is correct
67 Correct 122 ms 8880 KB Output is correct