Submission #105570

# Submission time Handle Problem Language Result Execution time Memory
105570 2019-04-13T13:50:36 Z Kastanda Jakarta Skyscrapers (APIO15_skyscraper) C++11
100 / 100
726 ms 2424 KB
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 30004;
int n, m, head[N], nxt[N], D[N];
pair < int , int > A[N];
priority_queue < pair < int , int > > Pq;
int main()
{
    memset(nxt, -1, sizeof(nxt));
    memset(head, -1, sizeof(head));
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++)
        scanf("%d%d", &A[i].x, &A[i].y), nxt[i] = head[A[i].x], head[A[i].x] = i;
    memset(D, 63, sizeof(D)); D[A[0].x] = 0;
    Pq.push({0, A[0].x});
    while (Pq.size())
    {
        int d = -Pq.top().x, v = Pq.top().y; Pq.pop();
        if (v == A[1].x)
            return !printf("%d\n", d);
        if (d > D[v]) continue;
        for (; ~ head[v]; head[v] = nxt[head[v]])
        {
            int dft = A[head[v]].y;
            d = D[v];
            for (int id = v + dft; id < n; id += dft)
                if (D[id] > (++ d)) D[id] = d, Pq.push({-d, id});
            d = D[v];
            for (int id = v - dft; id >= 0; id -= dft)
                if (D[id] > (++ d)) D[id] = d, Pq.push({-d, id});
        }
    }
    return !printf("-1\n");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:15:63: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &A[i].x, &A[i].y), nxt[i] = head[A[i].x], head[A[i].x] = i;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 612 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 768 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 4 ms 896 KB Output is correct
14 Correct 3 ms 640 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 684 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 3 ms 768 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
17 Correct 3 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 3 ms 768 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 2 ms 776 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 3 ms 768 KB Output is correct
31 Correct 3 ms 768 KB Output is correct
32 Correct 3 ms 768 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 3 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 688 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 3 ms 844 KB Output is correct
15 Correct 3 ms 768 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 3 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 3 ms 768 KB Output is correct
31 Correct 3 ms 768 KB Output is correct
32 Correct 3 ms 768 KB Output is correct
33 Correct 4 ms 768 KB Output is correct
34 Correct 4 ms 768 KB Output is correct
35 Correct 11 ms 1152 KB Output is correct
36 Correct 4 ms 768 KB Output is correct
37 Correct 8 ms 1152 KB Output is correct
38 Correct 13 ms 1280 KB Output is correct
39 Correct 10 ms 1152 KB Output is correct
40 Correct 15 ms 1280 KB Output is correct
41 Correct 13 ms 1280 KB Output is correct
42 Correct 9 ms 1152 KB Output is correct
43 Correct 8 ms 1152 KB Output is correct
44 Correct 45 ms 1152 KB Output is correct
45 Correct 13 ms 1280 KB Output is correct
46 Correct 11 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 3 ms 768 KB Output is correct
18 Correct 3 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 7 ms 768 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 768 KB Output is correct
24 Correct 5 ms 768 KB Output is correct
25 Correct 4 ms 768 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 4 ms 768 KB Output is correct
29 Correct 4 ms 768 KB Output is correct
30 Correct 3 ms 768 KB Output is correct
31 Correct 4 ms 768 KB Output is correct
32 Correct 4 ms 768 KB Output is correct
33 Correct 4 ms 768 KB Output is correct
34 Correct 4 ms 768 KB Output is correct
35 Correct 10 ms 1152 KB Output is correct
36 Correct 4 ms 768 KB Output is correct
37 Correct 9 ms 1152 KB Output is correct
38 Correct 10 ms 1280 KB Output is correct
39 Correct 13 ms 1152 KB Output is correct
40 Correct 14 ms 1280 KB Output is correct
41 Correct 12 ms 1408 KB Output is correct
42 Correct 9 ms 1152 KB Output is correct
43 Correct 8 ms 1164 KB Output is correct
44 Correct 48 ms 1152 KB Output is correct
45 Correct 14 ms 1280 KB Output is correct
46 Correct 11 ms 1280 KB Output is correct
47 Correct 10 ms 1788 KB Output is correct
48 Correct 11 ms 1152 KB Output is correct
49 Correct 8 ms 1024 KB Output is correct
50 Correct 7 ms 1024 KB Output is correct
51 Correct 18 ms 2424 KB Output is correct
52 Correct 24 ms 1916 KB Output is correct
53 Correct 11 ms 1536 KB Output is correct
54 Correct 4 ms 896 KB Output is correct
55 Correct 5 ms 896 KB Output is correct
56 Correct 726 ms 1536 KB Output is correct
57 Correct 5 ms 1912 KB Output is correct
58 Correct 715 ms 1280 KB Output is correct
59 Correct 10 ms 1408 KB Output is correct
60 Correct 16 ms 1536 KB Output is correct
61 Correct 16 ms 1408 KB Output is correct
62 Correct 12 ms 1152 KB Output is correct
63 Correct 42 ms 2300 KB Output is correct
64 Correct 39 ms 2296 KB Output is correct
65 Correct 28 ms 2296 KB Output is correct
66 Correct 41 ms 2300 KB Output is correct
67 Correct 38 ms 2324 KB Output is correct