Submission #676253

# Submission time Handle Problem Language Result Execution time Memory
676253 2022-12-30T01:31:58 Z lto5 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 6816 KB
#include <bits/stdc++.h>
using namespace std;

using TNode = pair<int64_t, int>;
const int N = 50005;

int p[N];
vector<int> g[N];
vector<int> rg[N];
int64_t d[N];
int n, m;

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

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int id_b;
    cin >> id_b >> p[i];
    g[i].emplace_back(id_b);
    rg[id_b].emplace_back(i);
  }

  memset(d, 0x3f, sizeof(d));
  d[0] = 0;
  priority_queue<TNode, vector<TNode>, greater<TNode>> pq;
  pq.emplace(d[0], 0);

  while (!pq.empty()) {
    int64_t du; int u;
    tie(du, u) = pq.top();
    pq.pop();

    if (d[u] != du) {
      continue;
    }

    if (u == 1) {
      cout << du;
      return 0;
    }

    for (int id_b : g[u]) {
      for (int nxt_b = id_b; nxt_b >= 0; nxt_b -= p[u]) {
        for (int v : rg[nxt_b]) {
          int cost = abs(nxt_b - id_b) / p[u];
          if (d[v] > d[u] + cost) {
            d[v] = d[u] + cost;
            pq.emplace(d[v], v);
          }
        }
      }

      for (int nxt_b = id_b; nxt_b < n; nxt_b += p[u]) {
        for (int v : rg[nxt_b]) {
          int cost = abs(nxt_b - id_b) / p[u];
          if (d[v] > d[u] + cost) {
            d[v] = d[u] + cost;
            pq.emplace(d[v], v);
          }
        }
      }
    }
  }

  cout << -1;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3072 KB Output is correct
3 Correct 2 ms 3068 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3068 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 3 ms 3072 KB Output is correct
3 Correct 2 ms 3068 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 3 ms 3028 KB Output is correct
6 Correct 3 ms 3028 KB Output is correct
7 Correct 2 ms 3064 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3156 KB Output is correct
12 Correct 2 ms 3156 KB Output is correct
13 Correct 40 ms 3204 KB Output is correct
14 Correct 4 ms 3332 KB Output is correct
15 Correct 4 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3068 KB Output is correct
2 Correct 2 ms 3040 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3064 KB Output is correct
11 Correct 2 ms 3156 KB Output is correct
12 Correct 2 ms 3200 KB Output is correct
13 Correct 37 ms 3156 KB Output is correct
14 Correct 4 ms 3284 KB Output is correct
15 Correct 4 ms 3372 KB Output is correct
16 Correct 2 ms 3076 KB Output is correct
17 Correct 3 ms 3284 KB Output is correct
18 Correct 2 ms 3040 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 27 ms 3308 KB Output is correct
21 Correct 3 ms 3084 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 3 ms 3028 KB Output is correct
24 Correct 4 ms 3140 KB Output is correct
25 Correct 2 ms 3156 KB Output is correct
26 Correct 2 ms 3084 KB Output is correct
27 Correct 2 ms 3156 KB Output is correct
28 Correct 2 ms 3156 KB Output is correct
29 Correct 3 ms 3156 KB Output is correct
30 Correct 3 ms 3028 KB Output is correct
31 Correct 3 ms 3028 KB Output is correct
32 Correct 2 ms 3028 KB Output is correct
33 Correct 4 ms 3284 KB Output is correct
34 Correct 4 ms 3284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3076 KB Output is correct
3 Correct 3 ms 3072 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3064 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3068 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3068 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3072 KB Output is correct
12 Correct 2 ms 3212 KB Output is correct
13 Correct 37 ms 3200 KB Output is correct
14 Correct 4 ms 3284 KB Output is correct
15 Correct 3 ms 3284 KB Output is correct
16 Correct 2 ms 3068 KB Output is correct
17 Correct 3 ms 3200 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3084 KB Output is correct
20 Correct 27 ms 3260 KB Output is correct
21 Correct 2 ms 3060 KB Output is correct
22 Correct 3 ms 3028 KB Output is correct
23 Correct 3 ms 3028 KB Output is correct
24 Correct 3 ms 3136 KB Output is correct
25 Correct 2 ms 3208 KB Output is correct
26 Correct 3 ms 3156 KB Output is correct
27 Correct 2 ms 3156 KB Output is correct
28 Correct 2 ms 3156 KB Output is correct
29 Correct 2 ms 3156 KB Output is correct
30 Correct 2 ms 3028 KB Output is correct
31 Correct 2 ms 3068 KB Output is correct
32 Correct 2 ms 3028 KB Output is correct
33 Correct 4 ms 3284 KB Output is correct
34 Correct 4 ms 3284 KB Output is correct
35 Correct 23 ms 5500 KB Output is correct
36 Correct 3 ms 3412 KB Output is correct
37 Correct 11 ms 5116 KB Output is correct
38 Correct 17 ms 6784 KB Output is correct
39 Correct 9 ms 4564 KB Output is correct
40 Correct 10 ms 5204 KB Output is correct
41 Correct 13 ms 6780 KB Output is correct
42 Correct 7 ms 4380 KB Output is correct
43 Correct 9 ms 5068 KB Output is correct
44 Execution timed out 1087 ms 5048 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3060 KB Output is correct
3 Correct 3 ms 3028 KB Output is correct
4 Correct 2 ms 3080 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3076 KB Output is correct
8 Correct 2 ms 3064 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3064 KB Output is correct
11 Correct 2 ms 3072 KB Output is correct
12 Correct 3 ms 3208 KB Output is correct
13 Correct 37 ms 3156 KB Output is correct
14 Correct 4 ms 3284 KB Output is correct
15 Correct 3 ms 3284 KB Output is correct
16 Correct 2 ms 3072 KB Output is correct
17 Correct 3 ms 3284 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 28 ms 3156 KB Output is correct
21 Correct 2 ms 3076 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 3 ms 3156 KB Output is correct
25 Correct 3 ms 3208 KB Output is correct
26 Correct 2 ms 3076 KB Output is correct
27 Correct 2 ms 3168 KB Output is correct
28 Correct 2 ms 3156 KB Output is correct
29 Correct 3 ms 3068 KB Output is correct
30 Correct 2 ms 3028 KB Output is correct
31 Correct 3 ms 3064 KB Output is correct
32 Correct 2 ms 3068 KB Output is correct
33 Correct 4 ms 3328 KB Output is correct
34 Correct 4 ms 3284 KB Output is correct
35 Correct 25 ms 5528 KB Output is correct
36 Correct 4 ms 3412 KB Output is correct
37 Correct 10 ms 5196 KB Output is correct
38 Correct 18 ms 6780 KB Output is correct
39 Correct 9 ms 4564 KB Output is correct
40 Correct 10 ms 5204 KB Output is correct
41 Correct 15 ms 6816 KB Output is correct
42 Correct 8 ms 4364 KB Output is correct
43 Correct 8 ms 5076 KB Output is correct
44 Execution timed out 1087 ms 5072 KB Time limit exceeded
45 Halted 0 ms 0 KB -