답안 #975811

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975811 2024-05-05T23:00:32 Z andro Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
158 ms 69688 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define F first
#define S second
 
const int N = 30010;
const int inf = 1e9;
int dist[N];
bool mark[N];
set<int> jumps[N];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> st;
vector<pair<int, int>> adj[N];
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int s, t;
    for(int i=0; i< m; i++){
        int a, b;
        cin >> a >> b;
        if(i==0)s=a;
        if(i==1)t=a;
        jumps[a].insert(b);
    }
    for(int i=0; i< n; i++){
        for(auto jump : jumps[i]){
            int cnt=1;
            for(int j=i-jump; j>=0; j-=jump){
                adj[i].pb({j, cnt});
                cnt++;
                if(jumps[j].find(jump)!=jumps[j].end())break;
            }
            cnt=1;
            for(int j=i+jump; j<n; j+=jump){
                adj[i].pb({j, cnt});
                cnt++;
                if(jumps[j].find(jump)!=jumps[j].end())break;
            }
        }
    }
    for(int i=0; i< n; i++)dist[i]=inf;
    dist[s]=0;
    st.push({0, s});
    while(st.size()){
        pair<int, int> nd = st.top();
        st.pop();
        if(mark[nd.S] || dist[nd.S]<nd.F)continue;
        mark[nd.S]=1;
        for(auto to : adj[nd.S]){
            if(to.S+nd.F<dist[to.F]){
                dist[to.F]=to.S+nd.F;
                st.push({dist[to.F], to.F});
            }
        }
    }
    if(dist[t]==inf)cout << -1 << '\n';
    else cout << dist[t] << '\n';
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:62:14: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |     if(dist[t]==inf)cout << -1 << '\n';
      |        ~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2632 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 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 2652 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 2 ms 2904 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 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 2648 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
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 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2740 KB Output is correct
15 Correct 1 ms 2664 KB Output is correct
16 Correct 1 ms 2664 KB Output is correct
17 Correct 2 ms 2920 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 1 ms 2664 KB Output is correct
20 Correct 1 ms 2664 KB Output is correct
21 Correct 1 ms 2664 KB Output is correct
22 Correct 1 ms 2664 KB Output is correct
23 Correct 2 ms 2660 KB Output is correct
24 Correct 2 ms 2916 KB Output is correct
25 Correct 2 ms 2920 KB Output is correct
26 Correct 1 ms 2664 KB Output is correct
27 Correct 1 ms 2664 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 4 ms 3416 KB Output is correct
30 Correct 2 ms 2904 KB Output is correct
31 Correct 2 ms 3164 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 5 ms 4116 KB Output is correct
34 Correct 5 ms 4188 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 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 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2480 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 1 ms 2840 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 3 ms 3420 KB Output is correct
30 Correct 1 ms 2904 KB Output is correct
31 Correct 2 ms 3164 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 5 ms 4188 KB Output is correct
34 Correct 5 ms 4188 KB Output is correct
35 Correct 11 ms 4824 KB Output is correct
36 Correct 2 ms 2908 KB Output is correct
37 Correct 13 ms 5508 KB Output is correct
38 Correct 15 ms 5720 KB Output is correct
39 Correct 15 ms 5724 KB Output is correct
40 Correct 15 ms 5740 KB Output is correct
41 Correct 15 ms 5748 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2920 KB Output is correct
44 Correct 4 ms 2920 KB Output is correct
45 Correct 16 ms 8808 KB Output is correct
46 Correct 17 ms 8604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2664 KB Output is correct
2 Correct 1 ms 2664 KB Output is correct
3 Correct 1 ms 2664 KB Output is correct
4 Correct 1 ms 2664 KB Output is correct
5 Correct 1 ms 2664 KB Output is correct
6 Correct 1 ms 2660 KB Output is correct
7 Correct 1 ms 2664 KB Output is correct
8 Correct 1 ms 2660 KB Output is correct
9 Correct 1 ms 2664 KB Output is correct
10 Correct 1 ms 2664 KB Output is correct
11 Correct 1 ms 2664 KB Output is correct
12 Correct 1 ms 2664 KB Output is correct
13 Correct 1 ms 2664 KB Output is correct
14 Correct 1 ms 2664 KB Output is correct
15 Correct 2 ms 2664 KB Output is correct
16 Correct 2 ms 2664 KB Output is correct
17 Correct 2 ms 2916 KB Output is correct
18 Correct 1 ms 2660 KB Output is correct
19 Correct 1 ms 2664 KB Output is correct
20 Correct 1 ms 2664 KB Output is correct
21 Correct 1 ms 2664 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 4 ms 3416 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 2908 KB Output is correct
33 Correct 5 ms 4188 KB Output is correct
34 Correct 5 ms 4188 KB Output is correct
35 Correct 12 ms 4952 KB Output is correct
36 Correct 3 ms 2908 KB Output is correct
37 Correct 12 ms 5468 KB Output is correct
38 Correct 15 ms 5724 KB Output is correct
39 Correct 15 ms 5724 KB Output is correct
40 Correct 15 ms 5724 KB Output is correct
41 Correct 15 ms 5724 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 5 ms 2952 KB Output is correct
44 Correct 4 ms 2908 KB Output is correct
45 Correct 19 ms 8696 KB Output is correct
46 Correct 16 ms 8792 KB Output is correct
47 Correct 31 ms 13012 KB Output is correct
48 Correct 11 ms 6356 KB Output is correct
49 Correct 9 ms 5212 KB Output is correct
50 Correct 7 ms 5048 KB Output is correct
51 Correct 32 ms 8408 KB Output is correct
52 Correct 35 ms 9044 KB Output is correct
53 Correct 13 ms 5844 KB Output is correct
54 Correct 3 ms 3164 KB Output is correct
55 Correct 4 ms 3540 KB Output is correct
56 Correct 8 ms 5208 KB Output is correct
57 Correct 26 ms 11744 KB Output is correct
58 Correct 7 ms 3796 KB Output is correct
59 Correct 7 ms 4312 KB Output is correct
60 Correct 8 ms 4824 KB Output is correct
61 Correct 8 ms 4316 KB Output is correct
62 Correct 16 ms 9432 KB Output is correct
63 Correct 55 ms 26820 KB Output is correct
64 Correct 62 ms 29920 KB Output is correct
65 Correct 84 ms 39624 KB Output is correct
66 Correct 156 ms 68920 KB Output is correct
67 Correct 158 ms 69688 KB Output is correct