답안 #243361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243361 2020-07-01T00:35:39 Z neihcr7j Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
227 ms 65864 KB
#include<bits/stdc++.h>

#define oo 100000000
#define maxn 30004

using namespace std;
typedef long long ll;

int n, m;

int b[maxn], p[maxn];
vector < pair < int, int > > g[maxn];

set < int > s[maxn];

int d[maxn];

int main(){
  #define TASK "ABC"
  //freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    cin >> b[i] >> p[i];
    s[b[i]].insert(p[i]);
  }

  for (int i = 0; i < n; ++i)
    for (auto p : s[i]) {
      for (int j = 1; i + j * p < n; ++j) {
        g[i].push_back({i + j * p, j});
        if (s[i + j * p].count(p))
          break;
      }
      for (int j = 1; i - j * p >= 0; ++j) {
        g[i].push_back({i - j * p, j});
        if (s[i - j * p].count(p))
          break;
      }
    }

  priority_queue < pair < int, int > > p;

  fill(d, d + n + 1, oo);

  d[b[0]] = 0;

  p.push({0, b[0]});

  while (!p.empty()) {
    int dist = p.top().first, u = p.top().second; p.pop();

    if (d[u] != -dist) continue;

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

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

  cout << (d[b[1]] == oo ? -1 : d[b[1]]);

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 7 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 7 ms 2560 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
12 Correct 7 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 7 ms 2688 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 7 ms 2480 KB Output is correct
7 Correct 7 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
12 Correct 7 ms 2560 KB Output is correct
13 Correct 6 ms 2560 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 8 ms 2688 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 8 ms 2816 KB Output is correct
18 Correct 6 ms 2592 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 8 ms 2688 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2612 KB Output is correct
23 Correct 7 ms 2688 KB Output is correct
24 Correct 7 ms 2688 KB Output is correct
25 Correct 7 ms 2688 KB Output is correct
26 Correct 7 ms 2560 KB Output is correct
27 Correct 7 ms 2560 KB Output is correct
28 Correct 7 ms 2816 KB Output is correct
29 Correct 8 ms 3232 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 8 ms 3072 KB Output is correct
32 Correct 8 ms 2792 KB Output is correct
33 Correct 11 ms 3836 KB Output is correct
34 Correct 11 ms 4012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2408 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
12 Correct 6 ms 2560 KB Output is correct
13 Correct 7 ms 2560 KB Output is correct
14 Correct 6 ms 2560 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 8 ms 2688 KB Output is correct
18 Correct 6 ms 2688 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 7 ms 2688 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 7 ms 2688 KB Output is correct
24 Correct 8 ms 2816 KB Output is correct
25 Correct 7 ms 2688 KB Output is correct
26 Correct 6 ms 2560 KB Output is correct
27 Correct 7 ms 2560 KB Output is correct
28 Correct 7 ms 2816 KB Output is correct
29 Correct 9 ms 3200 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 8 ms 2944 KB Output is correct
32 Correct 8 ms 2816 KB Output is correct
33 Correct 11 ms 3964 KB Output is correct
34 Correct 11 ms 3964 KB Output is correct
35 Correct 23 ms 4864 KB Output is correct
36 Correct 9 ms 2944 KB Output is correct
37 Correct 25 ms 5632 KB Output is correct
38 Correct 28 ms 5888 KB Output is correct
39 Correct 36 ms 5880 KB Output is correct
40 Correct 28 ms 5888 KB Output is correct
41 Correct 32 ms 5880 KB Output is correct
42 Correct 11 ms 2816 KB Output is correct
43 Correct 13 ms 2816 KB Output is correct
44 Correct 11 ms 2816 KB Output is correct
45 Correct 31 ms 8416 KB Output is correct
46 Correct 31 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
12 Correct 7 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 8 ms 2560 KB Output is correct
15 Correct 6 ms 2560 KB Output is correct
16 Correct 7 ms 2560 KB Output is correct
17 Correct 7 ms 2816 KB Output is correct
18 Correct 6 ms 2688 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 7 ms 2688 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 7 ms 2688 KB Output is correct
25 Correct 8 ms 2688 KB Output is correct
26 Correct 7 ms 2560 KB Output is correct
27 Correct 8 ms 2560 KB Output is correct
28 Correct 7 ms 2816 KB Output is correct
29 Correct 9 ms 3200 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 7 ms 2944 KB Output is correct
32 Correct 7 ms 2816 KB Output is correct
33 Correct 10 ms 3836 KB Output is correct
34 Correct 10 ms 3964 KB Output is correct
35 Correct 23 ms 4992 KB Output is correct
36 Correct 10 ms 2944 KB Output is correct
37 Correct 35 ms 5632 KB Output is correct
38 Correct 31 ms 5864 KB Output is correct
39 Correct 28 ms 6008 KB Output is correct
40 Correct 40 ms 5940 KB Output is correct
41 Correct 29 ms 5888 KB Output is correct
42 Correct 12 ms 3072 KB Output is correct
43 Correct 11 ms 2944 KB Output is correct
44 Correct 12 ms 3072 KB Output is correct
45 Correct 30 ms 8704 KB Output is correct
46 Correct 30 ms 8704 KB Output is correct
47 Correct 54 ms 13300 KB Output is correct
48 Correct 23 ms 6396 KB Output is correct
49 Correct 19 ms 5376 KB Output is correct
50 Correct 18 ms 4992 KB Output is correct
51 Correct 49 ms 8452 KB Output is correct
52 Correct 47 ms 8824 KB Output is correct
53 Correct 25 ms 6140 KB Output is correct
54 Correct 10 ms 3072 KB Output is correct
55 Correct 9 ms 3580 KB Output is correct
56 Correct 22 ms 5376 KB Output is correct
57 Correct 49 ms 11780 KB Output is correct
58 Correct 15 ms 3960 KB Output is correct
59 Correct 17 ms 4348 KB Output is correct
60 Correct 17 ms 5116 KB Output is correct
61 Correct 18 ms 4480 KB Output is correct
62 Correct 73 ms 9588 KB Output is correct
63 Correct 79 ms 25964 KB Output is correct
64 Correct 84 ms 29144 KB Output is correct
65 Correct 111 ms 38864 KB Output is correct
66 Correct 190 ms 65760 KB Output is correct
67 Correct 227 ms 65864 KB Output is correct