Submission #928132

# Submission time Handle Problem Language Result Execution time Memory
928132 2024-02-15T21:13:40 Z AlphaMale06 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
156 ms 68616 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';
      |        ~~~~~~^
# Verdict Execution time Memory 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 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 2648 KB Output is correct
# Verdict Execution time Memory 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 2648 KB Output is correct
5 Correct 1 ms 2656 KB Output is correct
6 Correct 1 ms 2648 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 2 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 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory 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 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 2 ms 2652 KB Output is correct
15 Correct 1 ms 2652 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 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2904 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 4 ms 3672 KB Output is correct
30 Correct 2 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 4136 KB Output is correct
34 Correct 5 ms 4188 KB Output is correct
# Verdict Execution time Memory 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 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2904 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 2 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
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 2 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 1 ms 2652 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 2904 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 3 ms 3420 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 2904 KB Output is correct
33 Correct 5 ms 4188 KB Output is correct
34 Correct 6 ms 4188 KB Output is correct
35 Correct 12 ms 4920 KB Output is correct
36 Correct 2 ms 2908 KB Output is correct
37 Correct 12 ms 5468 KB Output is correct
38 Correct 14 ms 5724 KB Output is correct
39 Correct 14 ms 5756 KB Output is correct
40 Correct 15 ms 5724 KB Output is correct
41 Correct 14 ms 5724 KB Output is correct
42 Correct 4 ms 2652 KB Output is correct
43 Correct 4 ms 2652 KB Output is correct
44 Correct 4 ms 2904 KB Output is correct
45 Correct 16 ms 8520 KB Output is correct
46 Correct 16 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2664 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 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 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2716 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 4 ms 2716 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 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 2652 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 3 ms 3420 KB Output is correct
30 Correct 2 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 11 ms 4700 KB Output is correct
36 Correct 2 ms 2908 KB Output is correct
37 Correct 12 ms 5580 KB Output is correct
38 Correct 15 ms 5724 KB Output is correct
39 Correct 16 ms 5696 KB Output is correct
40 Correct 15 ms 5724 KB Output is correct
41 Correct 14 ms 5724 KB Output is correct
42 Correct 4 ms 2692 KB Output is correct
43 Correct 4 ms 2652 KB Output is correct
44 Correct 5 ms 2696 KB Output is correct
45 Correct 16 ms 8540 KB Output is correct
46 Correct 16 ms 8540 KB Output is correct
47 Correct 31 ms 12800 KB Output is correct
48 Correct 11 ms 6104 KB Output is correct
49 Correct 9 ms 5168 KB Output is correct
50 Correct 7 ms 4700 KB Output is correct
51 Correct 27 ms 8200 KB Output is correct
52 Correct 28 ms 8540 KB Output is correct
53 Correct 12 ms 5588 KB Output is correct
54 Correct 2 ms 3164 KB Output is correct
55 Correct 3 ms 3664 KB Output is correct
56 Correct 8 ms 4956 KB Output is correct
57 Correct 27 ms 11816 KB Output is correct
58 Correct 7 ms 3540 KB Output is correct
59 Correct 7 ms 3972 KB Output is correct
60 Correct 9 ms 4620 KB Output is correct
61 Correct 9 ms 4056 KB Output is correct
62 Correct 16 ms 9184 KB Output is correct
63 Correct 55 ms 26384 KB Output is correct
64 Correct 61 ms 29644 KB Output is correct
65 Correct 82 ms 39364 KB Output is correct
66 Correct 155 ms 67900 KB Output is correct
67 Correct 156 ms 68616 KB Output is correct