답안 #757774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757774 2023-06-13T18:19:13 Z taher Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
175 ms 67288 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n , m;
  cin >> n >> m;
  vector<vector<pair<int,int>>> adj(n + 1);
  const int N = 30000 + 10;
  int s = -1 , d = -1;
  set<int> st[N];
  for(int i = 0 ; i < m ; i++){
    int a , b;
    cin >> a >> b;
    if(s == -1) s = a;
    else if(d == -1) d = a;
    st[a].insert(b);
  }
  for(int i = 0 ; i < n ; i++){
    for(auto x : st[i]){
      for(int j = i + x , cnt = 1 ; j < n ; j += x , cnt++){
        adj[i].emplace_back(j , cnt);
        if(st[j].find(x) != st[j].end()) break;
      }
      for(int j = i - x , cnt = 1 ; j >= 0 ; j -= x , cnt++){
        adj[i].emplace_back(j , cnt);
        if(st[j].find(x) != st[j].end()) break;
      }
    }
  }
  for(int i = 0 ; i < n ; i++) st[i].clear();
  priority_queue<pair<int,int> , vector<pair<int,int>> , greater<pair<int,int>>> pq;
  pq.emplace(0 , s);
  vector<int> dist(n + 1 , (int)1e9);
  dist[s] = 0;
  while(!pq.empty()){
    auto f = pq.top();
    pq.pop();
    if(f.second == d) break;
    if(f.first != dist[f.second]) continue;
    for(auto x : adj[f.second]){
      int node = x.first;
      int cost = x.second;
      if(dist[node] > f.first + cost){
        dist[node] = f.first + cost;
        pq.emplace(dist[node] , node);
      }
    }
  }
  if(dist[d] == (int)1e9) cout << -1 << '\n';
  else cout << dist[d] << '\n';
  return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1720 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 2 ms 1620 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 2 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1620 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
8 Correct 1 ms 1720 KB Output is correct
9 Correct 1 ms 1620 KB Output is correct
10 Correct 2 ms 1724 KB Output is correct
11 Correct 2 ms 1748 KB Output is correct
12 Correct 2 ms 1620 KB Output is correct
13 Correct 2 ms 1748 KB Output is correct
14 Correct 2 ms 1860 KB Output is correct
15 Correct 2 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1620 KB Output is correct
2 Correct 1 ms 1620 KB Output is correct
3 Correct 1 ms 1724 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 1 ms 1620 KB Output is correct
8 Correct 2 ms 1620 KB Output is correct
9 Correct 1 ms 1620 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 2 ms 1864 KB Output is correct
12 Correct 2 ms 1620 KB Output is correct
13 Correct 2 ms 1736 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1748 KB Output is correct
17 Correct 3 ms 2004 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 2 ms 1748 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 2 ms 1724 KB Output is correct
22 Correct 2 ms 1748 KB Output is correct
23 Correct 3 ms 1892 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 3 ms 1876 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 2128 KB Output is correct
29 Correct 5 ms 2516 KB Output is correct
30 Correct 3 ms 2116 KB Output is correct
31 Correct 3 ms 2236 KB Output is correct
32 Correct 3 ms 2128 KB Output is correct
33 Correct 7 ms 3284 KB Output is correct
34 Correct 7 ms 3444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1728 KB Output is correct
2 Correct 2 ms 1620 KB Output is correct
3 Correct 1 ms 1724 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 2 ms 1620 KB Output is correct
7 Correct 2 ms 1620 KB Output is correct
8 Correct 1 ms 1620 KB Output is correct
9 Correct 1 ms 1652 KB Output is correct
10 Correct 1 ms 1748 KB Output is correct
11 Correct 2 ms 1748 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 2 ms 1748 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 3 ms 1748 KB Output is correct
17 Correct 2 ms 2004 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 2 ms 1748 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 1 ms 1736 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
26 Correct 2 ms 1864 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 3 ms 2120 KB Output is correct
29 Correct 3 ms 2516 KB Output is correct
30 Correct 2 ms 2004 KB Output is correct
31 Correct 3 ms 2132 KB Output is correct
32 Correct 2 ms 2004 KB Output is correct
33 Correct 7 ms 3268 KB Output is correct
34 Correct 6 ms 3392 KB Output is correct
35 Correct 16 ms 4044 KB Output is correct
36 Correct 3 ms 2132 KB Output is correct
37 Correct 17 ms 4692 KB Output is correct
38 Correct 21 ms 5056 KB Output is correct
39 Correct 21 ms 5076 KB Output is correct
40 Correct 20 ms 5052 KB Output is correct
41 Correct 21 ms 5064 KB Output is correct
42 Correct 5 ms 1992 KB Output is correct
43 Correct 9 ms 2004 KB Output is correct
44 Correct 6 ms 2116 KB Output is correct
45 Correct 22 ms 7508 KB Output is correct
46 Correct 20 ms 7556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1620 KB Output is correct
2 Correct 1 ms 1748 KB Output is correct
3 Correct 1 ms 1620 KB Output is correct
4 Correct 1 ms 1620 KB Output is correct
5 Correct 1 ms 1620 KB Output is correct
6 Correct 1 ms 1620 KB Output is correct
7 Correct 2 ms 1620 KB Output is correct
8 Correct 2 ms 1620 KB Output is correct
9 Correct 1 ms 1724 KB Output is correct
10 Correct 2 ms 1724 KB Output is correct
11 Correct 2 ms 1748 KB Output is correct
12 Correct 2 ms 1724 KB Output is correct
13 Correct 2 ms 1748 KB Output is correct
14 Correct 3 ms 1956 KB Output is correct
15 Correct 3 ms 1876 KB Output is correct
16 Correct 2 ms 1724 KB Output is correct
17 Correct 3 ms 2004 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 2 ms 1860 KB Output is correct
20 Correct 3 ms 1876 KB Output is correct
21 Correct 2 ms 1748 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 2 ms 1860 KB Output is correct
28 Correct 2 ms 2124 KB Output is correct
29 Correct 4 ms 2516 KB Output is correct
30 Correct 2 ms 2004 KB Output is correct
31 Correct 3 ms 2132 KB Output is correct
32 Correct 3 ms 2132 KB Output is correct
33 Correct 7 ms 3284 KB Output is correct
34 Correct 5 ms 3400 KB Output is correct
35 Correct 17 ms 4040 KB Output is correct
36 Correct 4 ms 2092 KB Output is correct
37 Correct 17 ms 4712 KB Output is correct
38 Correct 19 ms 4988 KB Output is correct
39 Correct 20 ms 5076 KB Output is correct
40 Correct 20 ms 4984 KB Output is correct
41 Correct 22 ms 5204 KB Output is correct
42 Correct 9 ms 2004 KB Output is correct
43 Correct 7 ms 2000 KB Output is correct
44 Correct 5 ms 2132 KB Output is correct
45 Correct 20 ms 7512 KB Output is correct
46 Correct 20 ms 7496 KB Output is correct
47 Correct 37 ms 12052 KB Output is correct
48 Correct 17 ms 5932 KB Output is correct
49 Correct 12 ms 4948 KB Output is correct
50 Correct 11 ms 4728 KB Output is correct
51 Correct 29 ms 7368 KB Output is correct
52 Correct 30 ms 7884 KB Output is correct
53 Correct 19 ms 5200 KB Output is correct
54 Correct 4 ms 3004 KB Output is correct
55 Correct 4 ms 3408 KB Output is correct
56 Correct 16 ms 4952 KB Output is correct
57 Correct 14 ms 11348 KB Output is correct
58 Correct 8 ms 3660 KB Output is correct
59 Correct 9 ms 4048 KB Output is correct
60 Correct 10 ms 4676 KB Output is correct
61 Correct 9 ms 4000 KB Output is correct
62 Correct 21 ms 9168 KB Output is correct
63 Correct 64 ms 26252 KB Output is correct
64 Correct 68 ms 29632 KB Output is correct
65 Correct 103 ms 39100 KB Output is correct
66 Correct 175 ms 67288 KB Output is correct
67 Correct 126 ms 66908 KB Output is correct