답안 #506208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
506208 2022-01-11T21:25:41 Z Abrar_Al_Samit Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
532 ms 2424 KB
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+5;
const int MX = 2001;
int n, m;
map<int,int>nodes[MX];
priority_queue<pair<int,int>>pq;
int dist[MX];
bool vis[MX];
vector<int>dvs[MX];

void PlayGround() {
  cin >> n >> m;
  for(int dv=1; dv<=n; ++dv) {
    for(int i=1; dv*i<=n; ++i) {
      dvs[dv*i].push_back(dv);
    }
  }

  int b[2];
  for(int i=0; i<m; ++i) {
    int _b, p;
    cin >> _b >> p;
    if(i<2) {
      b[i] = _b;
    }
    nodes[_b][p] = 1;
  }
  for(int i=0; i<n; ++i) {
    dist[i] = INF;
  }
  dist[b[1]] = 0;
  pq.emplace(0, b[1]);
  while(!pq.empty()) {
    int d, v;
    tie(d, v) = pq.top();
    d = -d;
    pq.pop();
    if(vis[v]) continue;
    vis[v] = 1;

    for(int i=0; i<n; ++i) if(i!=v) {
      int gap = abs(i-v);
      int need = INF;
      for(int dv : dvs[gap]) {
        if(nodes[i].count(dv)) {
          need = min(need, gap/dv);
        }
      }
      if(d+need<dist[i]) {
        dist[i] = d+need;
        pq.emplace(-dist[i], i);
      }
    }
  }

  if(dist[b[0]]==INF) {
    dist[b[0]] = -1;
  }

  cout << dist[b[0]] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 412 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 24 ms 588 KB Output is correct
18 Correct 17 ms 636 KB Output is correct
19 Correct 4 ms 584 KB Output is correct
20 Correct 108 ms 728 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 6 ms 588 KB Output is correct
23 Correct 11 ms 620 KB Output is correct
24 Correct 45 ms 792 KB Output is correct
25 Correct 18 ms 588 KB Output is correct
26 Correct 4 ms 600 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 50 ms 692 KB Output is correct
29 Correct 2 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 584 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 23 ms 588 KB Output is correct
18 Correct 15 ms 632 KB Output is correct
19 Correct 4 ms 588 KB Output is correct
20 Correct 111 ms 716 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 5 ms 588 KB Output is correct
23 Correct 9 ms 716 KB Output is correct
24 Correct 43 ms 696 KB Output is correct
25 Correct 17 ms 692 KB Output is correct
26 Correct 4 ms 588 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 51 ms 588 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 2 ms 588 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 255 ms 2004 KB Output is correct
36 Correct 59 ms 716 KB Output is correct
37 Correct 442 ms 1724 KB Output is correct
38 Correct 501 ms 2292 KB Output is correct
39 Correct 488 ms 2420 KB Output is correct
40 Correct 504 ms 2296 KB Output is correct
41 Correct 493 ms 2336 KB Output is correct
42 Correct 7 ms 716 KB Output is correct
43 Correct 6 ms 728 KB Output is correct
44 Correct 111 ms 980 KB Output is correct
45 Correct 10 ms 2148 KB Output is correct
46 Correct 19 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 25 ms 588 KB Output is correct
18 Correct 13 ms 632 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 112 ms 724 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 5 ms 588 KB Output is correct
23 Correct 10 ms 616 KB Output is correct
24 Correct 43 ms 700 KB Output is correct
25 Correct 17 ms 588 KB Output is correct
26 Correct 4 ms 588 KB Output is correct
27 Correct 3 ms 588 KB Output is correct
28 Correct 51 ms 688 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 248 ms 2000 KB Output is correct
36 Correct 50 ms 716 KB Output is correct
37 Correct 444 ms 1808 KB Output is correct
38 Correct 494 ms 2424 KB Output is correct
39 Correct 532 ms 2296 KB Output is correct
40 Correct 486 ms 2296 KB Output is correct
41 Correct 495 ms 2332 KB Output is correct
42 Correct 8 ms 708 KB Output is correct
43 Correct 6 ms 716 KB Output is correct
44 Correct 124 ms 816 KB Output is correct
45 Correct 11 ms 2144 KB Output is correct
46 Correct 21 ms 2180 KB Output is correct
47 Runtime error 1 ms 972 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -