답안 #970732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970732 2024-04-27T07:23:07 Z kilkuwu Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
401 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 (it != doges[to].end() && it->first == power) {
          break;
        }
        adj[i].emplace_back(w, to);
      } 
      for (int w = 1; i - w * power >= 0; w++) {
        int to = i - w * power;
        auto it = doges[to].find({power, -1});
        if (it != doges[to].end() && it->first == power) {
          break;
        }
        adj[i].emplace_back(w, to);
      }
    } 
  }

  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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 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
# 결과 실행 시간 메모리 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 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 2648 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 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 1 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 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 2804 KB Output is correct
5 Correct 1 ms 2904 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 2652 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2816 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 2908 KB Output is correct
17 Correct 2 ms 3160 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 49 ms 34864 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 2 ms 2916 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 1 ms 2820 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 2 ms 3164 KB Output is correct
29 Correct 2 ms 3420 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 3164 KB Output is correct
32 Correct 2 ms 3160 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 4 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 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 2648 KB Output is correct
6 Correct 1 ms 2648 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 2652 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 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 3164 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 46 ms 34868 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2908 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 2912 KB Output is correct
26 Correct 1 ms 2932 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 2 ms 3164 KB Output is correct
29 Correct 3 ms 3420 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 3164 KB Output is correct
32 Correct 2 ms 3064 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 3 ms 4188 KB Output is correct
35 Correct 14 ms 5652 KB Output is correct
36 Correct 3 ms 3164 KB Output is correct
37 Correct 18 ms 6996 KB Output is correct
38 Correct 19 ms 6748 KB Output is correct
39 Correct 19 ms 7004 KB Output is correct
40 Correct 19 ms 6864 KB Output is correct
41 Correct 19 ms 6744 KB Output is correct
42 Correct 6 ms 3164 KB Output is correct
43 Correct 4 ms 3080 KB Output is correct
44 Correct 46 ms 35156 KB Output is correct
45 Correct 16 ms 8540 KB Output is correct
46 Correct 16 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2900 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 2 ms 2808 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2816 KB Output is correct
10 Correct 1 ms 2652 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 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 2 ms 3164 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2904 KB Output is correct
20 Correct 46 ms 34980 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 2 ms 2908 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2996 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 2 ms 3124 KB Output is correct
29 Correct 2 ms 3420 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 2 ms 3164 KB Output is correct
32 Correct 2 ms 2912 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 14 ms 5752 KB Output is correct
36 Correct 2 ms 3164 KB Output is correct
37 Correct 17 ms 6780 KB Output is correct
38 Correct 19 ms 6748 KB Output is correct
39 Correct 20 ms 7208 KB Output is correct
40 Correct 19 ms 7000 KB Output is correct
41 Correct 18 ms 6748 KB Output is correct
42 Correct 4 ms 3164 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 49 ms 35220 KB Output is correct
45 Correct 16 ms 8536 KB Output is correct
46 Correct 21 ms 8540 KB Output is correct
47 Correct 41 ms 15396 KB Output is correct
48 Correct 12 ms 6360 KB Output is correct
49 Correct 9 ms 5616 KB Output is correct
50 Correct 7 ms 5212 KB Output is correct
51 Correct 30 ms 9260 KB Output is correct
52 Correct 32 ms 9564 KB Output is correct
53 Correct 13 ms 5984 KB Output is correct
54 Correct 2 ms 3420 KB Output is correct
55 Correct 3 ms 3700 KB Output is correct
56 Runtime error 401 ms 262144 KB Execution killed with signal 9
57 Halted 0 ms 0 KB -