Submission #666526

# Submission time Handle Problem Language Result Execution time Memory
666526 2022-11-28T21:00:59 Z Farbod Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
675 ms 3820 KB
#include <iostream>
#include <vector>
#include <set>
using namespace std;

const int N = 30005, inf = 1e9;

int n, m, x[N];
vector <int> v[N];

int d[N];
set <pair <int, int>> q;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int p;
        cin >> x[i] >> p, v[x[i]].push_back(p);
    }

    int tmp = x[1];
    for (int i = 0; i < n; i++)
        d[i] = inf;

    d[x[0]] = 0, q.insert({0, x[0]});
    while (q.size()) {
        int x = q.begin() -> second;
        q.erase(q.begin());

        if (x == tmp)
            return cout << d[x], 0;

        for (int i = 0; i < v[x].size(); i++) {
            int j = v[x][i];
            for (int k = 1; x + k * j < n; k++)
                if (d[x] + k < d[x + k * j])
                    q.erase({d[x + k * j], x + k * j}),
                    d[x + k * j] = d[x] + k,
                    q.insert({d[x + k * j], x + k * j});
            for (int k = 1; x - k * j >= 0; k++)
                if (d[x] + k < d[x - k * j])
                    q.erase({d[x - k * j], x - k * j}),
                    d[x - k * j] = d[x] + k,
                    q.insert({d[x - k * j], x - k * j});
        }
    }

    cout << -1;

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int i = 0; i < v[x].size(); i++) {
      |                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1044 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 1040 KB Output is correct
9 Correct 2 ms 1040 KB Output is correct
10 Correct 1 ms 1036 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1040 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1036 KB Output is correct
4 Correct 1 ms 1040 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1040 KB Output is correct
10 Correct 1 ms 1036 KB Output is correct
11 Correct 1 ms 1176 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 1052 KB Output is correct
15 Correct 1 ms 1052 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 1056 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 2 ms 1060 KB Output is correct
20 Correct 5 ms 1224 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 1 ms 1108 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 2 ms 1108 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 1064 KB Output is correct
28 Correct 2 ms 1048 KB Output is correct
29 Correct 3 ms 1112 KB Output is correct
30 Correct 2 ms 1112 KB Output is correct
31 Correct 2 ms 1108 KB Output is correct
32 Correct 2 ms 1108 KB Output is correct
33 Correct 4 ms 1108 KB Output is correct
34 Correct 4 ms 1180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1040 KB Output is correct
4 Correct 1 ms 1040 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 1036 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1040 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1044 KB Output is correct
17 Correct 2 ms 1108 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 6 ms 1108 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1092 KB Output is correct
25 Correct 1 ms 1108 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 4 ms 1116 KB Output is correct
30 Correct 2 ms 1040 KB Output is correct
31 Correct 2 ms 1112 KB Output is correct
32 Correct 2 ms 1052 KB Output is correct
33 Correct 5 ms 1116 KB Output is correct
34 Correct 4 ms 1116 KB Output is correct
35 Correct 7 ms 1564 KB Output is correct
36 Correct 2 ms 1116 KB Output is correct
37 Correct 6 ms 1488 KB Output is correct
38 Correct 8 ms 1756 KB Output is correct
39 Correct 6 ms 1632 KB Output is correct
40 Correct 6 ms 1620 KB Output is correct
41 Correct 7 ms 1720 KB Output is correct
42 Correct 4 ms 1620 KB Output is correct
43 Correct 5 ms 1552 KB Output is correct
44 Correct 49 ms 1640 KB Output is correct
45 Correct 8 ms 1552 KB Output is correct
46 Correct 8 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 1044 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 980 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 2 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 1044 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 1108 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 1040 KB Output is correct
20 Correct 4 ms 1184 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 1040 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 2 ms 1108 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 2 ms 1108 KB Output is correct
28 Correct 2 ms 1140 KB Output is correct
29 Correct 4 ms 1108 KB Output is correct
30 Correct 2 ms 1108 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 2 ms 1108 KB Output is correct
33 Correct 4 ms 1108 KB Output is correct
34 Correct 4 ms 1184 KB Output is correct
35 Correct 7 ms 1536 KB Output is correct
36 Correct 3 ms 1108 KB Output is correct
37 Correct 6 ms 1436 KB Output is correct
38 Correct 8 ms 1692 KB Output is correct
39 Correct 6 ms 1576 KB Output is correct
40 Correct 7 ms 1696 KB Output is correct
41 Correct 11 ms 1676 KB Output is correct
42 Correct 5 ms 1572 KB Output is correct
43 Correct 6 ms 1568 KB Output is correct
44 Correct 52 ms 1632 KB Output is correct
45 Correct 9 ms 1572 KB Output is correct
46 Correct 9 ms 1632 KB Output is correct
47 Correct 27 ms 2328 KB Output is correct
48 Correct 5 ms 1888 KB Output is correct
49 Correct 5 ms 1832 KB Output is correct
50 Correct 4 ms 1632 KB Output is correct
51 Correct 43 ms 3592 KB Output is correct
52 Correct 37 ms 3308 KB Output is correct
53 Correct 11 ms 3036 KB Output is correct
54 Correct 5 ms 1756 KB Output is correct
55 Correct 6 ms 1756 KB Output is correct
56 Correct 675 ms 3820 KB Output is correct
57 Correct 21 ms 2512 KB Output is correct
58 Correct 642 ms 2200 KB Output is correct
59 Correct 11 ms 2332 KB Output is correct
60 Correct 10 ms 2260 KB Output is correct
61 Correct 11 ms 2304 KB Output is correct
62 Correct 10 ms 2516 KB Output is correct
63 Correct 58 ms 3076 KB Output is correct
64 Correct 64 ms 3064 KB Output is correct
65 Correct 74 ms 3028 KB Output is correct
66 Correct 97 ms 3028 KB Output is correct
67 Correct 95 ms 3040 KB Output is correct