Submission #970891

# Submission time Handle Problem Language Result Execution time Memory
970891 2024-04-27T13:11:31 Z kilkuwu Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
392 ms 262144 KB
#include <bits/stdc++.h>

#define nl '\n'

const int mxN = 30006;
std::set<std::pair<int, int>> doges[mxN];
int B[mxN], P[mxN];
int N, M;

std::vector<std::pair<int, int>> adj[mxN];

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  std::cin >> N >> M;
  
  for (int i = 0; i < M; i++) {
    std::cin >> B[i] >> P[i];

    auto it = doges[B[i]].lower_bound({P[i], -1});

    if (it == doges[B[i]].end() || it->first != P[i]) {
      doges[B[i]].insert({P[i], i});
    }
  }

  if (B[0] == B[1]) {
    std::cout << 0 << nl;
    return 0;
  }

  for (int i = 0; i < N; i++) {
    for (auto [power, id] : doges[i]) {
      for (int w = 1; i + w * power < N; w++) {
        int to = i + w * power;
        auto it = doges[to].find({power, -1});
        if (doges[to].size()) {
          adj[i].emplace_back(w, to);
        }
        if (it != doges[to].end() && it->first == power) {
          break;
        }
      } 
      for (int w = 1; i - w * power >= 0; w++) {
        int to = i - w * power;
        auto it = doges[to].find({power, -1});
        if (doges[to].size()) {
          adj[i].emplace_back(w, to);
        }
        if (it != doges[to].end() && it->first == power) {
          break;
        }
      }
    } 
  }

  auto dijkstra = [&](int s) -> int {
    std::priority_queue<std::pair<int, int>> pq;
    std::vector<int> dp(N, 1e9);
    dp[s] = 0;

    pq.push({0, s});
    while (pq.size()) {
      auto [d, u] = pq.top();
      d = -d;
      pq.pop();
      if (dp[u] < d) continue;

      for (auto [w, v] : adj[u]) {
        if (dp[v] > d + w) {
          dp[v] = d + w;
          pq.emplace(-dp[v], v);
        } 
      }
    }

    return dp[B[1]] < 1e9 ? dp[B[1]] : -1;
  };

  std::cout << dijkstra(B[0]) << nl;
}
# 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 2804 KB Output is correct
4 Correct 1 ms 2804 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
# 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 2812 KB Output is correct
5 Correct 1 ms 2900 KB Output is correct
6 Correct 1 ms 2804 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 2 ms 2808 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 2 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2748 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 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 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 2656 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 4 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 47 ms 34848 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 3 ms 2648 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 2 ms 2904 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 2 ms 2648 KB Output is correct
28 Correct 1 ms 3164 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 1 ms 2808 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 2904 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 2648 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 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2904 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 2 ms 2780 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2728 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 48 ms 34900 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2812 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 2 ms 2652 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 2 ms 3164 KB Output is correct
29 Correct 1 ms 2808 KB Output is correct
30 Correct 1 ms 2652 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 3 ms 2908 KB Output is correct
35 Correct 14 ms 5720 KB Output is correct
36 Correct 3 ms 3164 KB Output is correct
37 Correct 17 ms 7000 KB Output is correct
38 Correct 20 ms 6748 KB Output is correct
39 Correct 19 ms 7028 KB Output is correct
40 Correct 19 ms 7004 KB Output is correct
41 Correct 20 ms 6728 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 52 ms 35464 KB Output is correct
45 Correct 17 ms 4696 KB Output is correct
46 Correct 16 ms 4700 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 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 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2904 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 50 ms 34896 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2812 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2820 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 3164 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 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 2816 KB Output is correct
35 Correct 14 ms 5724 KB Output is correct
36 Correct 3 ms 3164 KB Output is correct
37 Correct 18 ms 7000 KB Output is correct
38 Correct 21 ms 6736 KB Output is correct
39 Correct 21 ms 7004 KB Output is correct
40 Correct 20 ms 7004 KB Output is correct
41 Correct 19 ms 6900 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 50 ms 35220 KB Output is correct
45 Correct 13 ms 4696 KB Output is correct
46 Correct 13 ms 4700 KB Output is correct
47 Correct 43 ms 13784 KB Output is correct
48 Correct 11 ms 5720 KB Output is correct
49 Correct 9 ms 4956 KB Output is correct
50 Correct 7 ms 4444 KB Output is correct
51 Correct 24 ms 7472 KB Output is correct
52 Correct 25 ms 7892 KB Output is correct
53 Correct 11 ms 5524 KB Output is correct
54 Correct 1 ms 2800 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Runtime error 392 ms 262144 KB Execution killed with signal 9
57 Halted 0 ms 0 KB -