Submission #477406

# Submission time Handle Problem Language Result Execution time Memory
477406 2021-10-02T03:54:47 Z KienTran Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
355 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

const int O = 3e4 + 5;
const int N = 2e3 + 5;
const int inf = 1e9;

int n, m, b[O], p[O], d[O];
vector <pair <int, int>> g[O];
vector <int> a[O];

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++ i){
        cin >> b[i] >> p[i];
        a[b[i]].push_back(p[i]);
    }

    for (int i = 0; i < n; ++ i){
        for (int j : a[i]){
            for (int z = i % j; z < n; z += j){
                if (z != i){
                    g[i].push_back({z, abs(i - z) / j});
                }
            }
        }
    }

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

    priority_queue <pair <int, int>> q;
    q.push({0, b[1]}); d[b[1]] = 0;

    while (q.size()){
        int u = q.top().second;
        int du = -q.top().first;

        q.pop();
        if (d[u] != du) continue;

        for (auto i : g[u]){
            int v = i.first;
            int w = i.second;

            if (d[v] > d[u] + w){
                d[v] = d[u] + w;
                q.push({-d[v], v});
            }
        }
    }

    if (d[b[2]] >= 1e9) d[b[2]] = -1;
    cout << d[b[2]];
}

Compilation message

skyscraper.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1740 KB Output is correct
9 Correct 1 ms 1740 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 1 ms 1868 KB Output is correct
12 Correct 5 ms 3912 KB Output is correct
13 Correct 5 ms 4036 KB Output is correct
14 Correct 1 ms 1740 KB Output is correct
15 Correct 1 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1740 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 5 ms 3912 KB Output is correct
13 Correct 6 ms 4036 KB Output is correct
14 Correct 1 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1996 KB Output is correct
18 Correct 1 ms 1740 KB Output is correct
19 Correct 1 ms 1740 KB Output is correct
20 Correct 66 ms 33876 KB Output is correct
21 Correct 1 ms 1740 KB Output is correct
22 Correct 1 ms 1740 KB Output is correct
23 Correct 2 ms 1740 KB Output is correct
24 Correct 3 ms 1868 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 66 ms 34716 KB Output is correct
27 Correct 61 ms 34652 KB Output is correct
28 Correct 2 ms 1996 KB Output is correct
29 Correct 3 ms 2380 KB Output is correct
30 Correct 2 ms 1996 KB Output is correct
31 Correct 2 ms 2124 KB Output is correct
32 Correct 2 ms 1996 KB Output is correct
33 Correct 4 ms 2892 KB Output is correct
34 Correct 4 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1740 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 5 ms 3912 KB Output is correct
13 Correct 5 ms 4036 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1996 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 1 ms 1740 KB Output is correct
20 Correct 65 ms 33872 KB Output is correct
21 Correct 1 ms 1740 KB Output is correct
22 Correct 1 ms 1740 KB Output is correct
23 Correct 2 ms 1740 KB Output is correct
24 Correct 2 ms 1868 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 64 ms 34772 KB Output is correct
27 Correct 63 ms 34728 KB Output is correct
28 Correct 2 ms 1996 KB Output is correct
29 Correct 3 ms 2448 KB Output is correct
30 Correct 2 ms 1996 KB Output is correct
31 Correct 3 ms 2124 KB Output is correct
32 Correct 2 ms 1996 KB Output is correct
33 Correct 4 ms 3008 KB Output is correct
34 Correct 5 ms 3020 KB Output is correct
35 Correct 12 ms 3548 KB Output is correct
36 Correct 3 ms 1996 KB Output is correct
37 Correct 12 ms 5124 KB Output is correct
38 Correct 12 ms 4632 KB Output is correct
39 Correct 13 ms 4744 KB Output is correct
40 Correct 12 ms 4804 KB Output is correct
41 Correct 14 ms 4556 KB Output is correct
42 Runtime error 340 ms 262148 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1644 KB Output is correct
9 Correct 2 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 5 ms 3912 KB Output is correct
13 Correct 5 ms 3980 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 1 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1996 KB Output is correct
18 Correct 1 ms 1740 KB Output is correct
19 Correct 1 ms 1740 KB Output is correct
20 Correct 64 ms 33804 KB Output is correct
21 Correct 1 ms 1740 KB Output is correct
22 Correct 1 ms 1740 KB Output is correct
23 Correct 2 ms 1740 KB Output is correct
24 Correct 2 ms 1868 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 66 ms 34796 KB Output is correct
27 Correct 61 ms 34672 KB Output is correct
28 Correct 3 ms 1996 KB Output is correct
29 Correct 5 ms 2380 KB Output is correct
30 Correct 2 ms 1996 KB Output is correct
31 Correct 3 ms 2136 KB Output is correct
32 Correct 3 ms 2008 KB Output is correct
33 Correct 4 ms 2904 KB Output is correct
34 Correct 4 ms 3032 KB Output is correct
35 Correct 11 ms 3664 KB Output is correct
36 Correct 3 ms 2008 KB Output is correct
37 Correct 11 ms 5208 KB Output is correct
38 Correct 12 ms 4660 KB Output is correct
39 Correct 15 ms 4812 KB Output is correct
40 Correct 13 ms 4684 KB Output is correct
41 Correct 13 ms 4556 KB Output is correct
42 Runtime error 355 ms 262148 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -