Submission #441698

# Submission time Handle Problem Language Result Execution time Memory
441698 2021-07-05T20:34:23 Z julian33 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
129 ms 7720 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int mxN=3e4;

int n,m,p,b,dist[mxN],seen[mxN];
set<int> jump[mxN];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    cin>>n>>m;
    for(int i=0;i<n;i++)
        dist[i]=1e9;
    int s,e;
    for(int i=0;i<m;i++){
        cin>>b>>p;
        if(i==0)
            s=b;
        if(i==1)
            e=b;
        jump[b].insert(p);
    }
    priority_queue<pii,vector<pii>,greater<pii>> q;
    q.push({0,s}); dist[s]=0;
    while(!q.empty()){
        int at=q.top().second; q.pop();
        if(at==e)
            break;
        if(seen[at])
            continue;
        seen[at]=1;
        // cout<<at<<"\n";
        for(int i:jump[at]){
            for(int j=1;j<=n;j++){
                if(at+i*j>=n)
                    break;
                if(dist[at]+j<dist[at+i*j]){
                    dist[at+i*j]=dist[at]+j;
                    q.push({dist[at+i*j],at+i*j});
                }
                if(jump[at+i*j].count(i))
                    break;
            }
            for(int j=1;j<=n;j++){
                if(at-i*j<0)
                    break;
                if(dist[at]+j<dist[at-i*j]){
                    dist[at-i*j]=dist[at]+j;
                    q.push({dist[at-i*j],at-i*j});
                }
                if(jump[at-i*j].count(i))
                    break;
            }
        }
    }
    cout<<(dist[e]==1e9?-1:dist[e])<<"\n";
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:27: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |     q.push({0,s}); dist[s]=0;
      |                    ~~~~~~~^~
skyscraper.cpp:68:18: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |     cout<<(dist[e]==1e9?-1:dist[e])<<"\n";
      |            ~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1724 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1720 KB Output is correct
11 Correct 2 ms 1740 KB Output is correct
12 Correct 2 ms 1736 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 3 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1720 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1724 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1728 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1732 KB Output is correct
12 Correct 2 ms 1740 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 2 ms 1740 KB Output is correct
17 Correct 2 ms 1736 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 1 ms 1732 KB Output is correct
20 Correct 2 ms 1740 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 2 ms 1720 KB Output is correct
23 Correct 2 ms 1736 KB Output is correct
24 Correct 2 ms 1868 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 2 ms 1740 KB Output is correct
27 Correct 2 ms 1740 KB Output is correct
28 Correct 2 ms 1740 KB Output is correct
29 Correct 4 ms 1996 KB Output is correct
30 Correct 2 ms 1740 KB Output is correct
31 Correct 2 ms 1868 KB Output is correct
32 Correct 2 ms 1868 KB Output is correct
33 Correct 5 ms 2124 KB Output is correct
34 Correct 4 ms 2108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 1 ms 1720 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1740 KB Output is correct
12 Correct 2 ms 1736 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 3 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1744 KB Output is correct
18 Correct 2 ms 1740 KB Output is correct
19 Correct 1 ms 1740 KB Output is correct
20 Correct 2 ms 1740 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 1 ms 1740 KB Output is correct
23 Correct 2 ms 1740 KB Output is correct
24 Correct 2 ms 1868 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 2 ms 1740 KB Output is correct
27 Correct 2 ms 1740 KB Output is correct
28 Correct 2 ms 1740 KB Output is correct
29 Correct 3 ms 1996 KB Output is correct
30 Correct 2 ms 1740 KB Output is correct
31 Correct 2 ms 1868 KB Output is correct
32 Correct 2 ms 1848 KB Output is correct
33 Correct 5 ms 2124 KB Output is correct
34 Correct 5 ms 2124 KB Output is correct
35 Correct 15 ms 3148 KB Output is correct
36 Correct 3 ms 1996 KB Output is correct
37 Correct 13 ms 2904 KB Output is correct
38 Correct 15 ms 3404 KB Output is correct
39 Correct 13 ms 3356 KB Output is correct
40 Correct 13 ms 3408 KB Output is correct
41 Correct 14 ms 3516 KB Output is correct
42 Correct 6 ms 1860 KB Output is correct
43 Correct 7 ms 1964 KB Output is correct
44 Correct 7 ms 1996 KB Output is correct
45 Correct 20 ms 3736 KB Output is correct
46 Correct 18 ms 3632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 2 ms 1724 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1724 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1720 KB Output is correct
11 Correct 2 ms 1740 KB Output is correct
12 Correct 2 ms 1740 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 2 ms 1740 KB Output is correct
18 Correct 1 ms 1740 KB Output is correct
19 Correct 1 ms 1740 KB Output is correct
20 Correct 2 ms 1740 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 1 ms 1740 KB Output is correct
23 Correct 2 ms 1740 KB Output is correct
24 Correct 2 ms 1864 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 2 ms 1740 KB Output is correct
27 Correct 2 ms 1740 KB Output is correct
28 Correct 2 ms 1740 KB Output is correct
29 Correct 4 ms 1996 KB Output is correct
30 Correct 2 ms 1740 KB Output is correct
31 Correct 2 ms 1868 KB Output is correct
32 Correct 2 ms 1868 KB Output is correct
33 Correct 5 ms 2124 KB Output is correct
34 Correct 4 ms 2124 KB Output is correct
35 Correct 16 ms 3148 KB Output is correct
36 Correct 3 ms 1996 KB Output is correct
37 Correct 13 ms 2888 KB Output is correct
38 Correct 15 ms 3404 KB Output is correct
39 Correct 13 ms 3400 KB Output is correct
40 Correct 14 ms 3404 KB Output is correct
41 Correct 13 ms 3404 KB Output is correct
42 Correct 6 ms 1864 KB Output is correct
43 Correct 6 ms 1868 KB Output is correct
44 Correct 7 ms 1988 KB Output is correct
45 Correct 19 ms 3720 KB Output is correct
46 Correct 18 ms 3660 KB Output is correct
47 Correct 19 ms 3780 KB Output is correct
48 Correct 9 ms 3020 KB Output is correct
49 Correct 8 ms 3020 KB Output is correct
50 Correct 6 ms 2628 KB Output is correct
51 Correct 22 ms 4272 KB Output is correct
52 Correct 23 ms 4296 KB Output is correct
53 Correct 13 ms 3788 KB Output is correct
54 Correct 3 ms 2124 KB Output is correct
55 Correct 3 ms 2124 KB Output is correct
56 Correct 13 ms 3532 KB Output is correct
57 Correct 3 ms 2252 KB Output is correct
58 Correct 8 ms 2244 KB Output is correct
59 Correct 9 ms 2336 KB Output is correct
60 Correct 9 ms 2380 KB Output is correct
61 Correct 10 ms 2508 KB Output is correct
62 Correct 15 ms 3656 KB Output is correct
63 Correct 52 ms 5568 KB Output is correct
64 Correct 53 ms 5560 KB Output is correct
65 Correct 68 ms 5680 KB Output is correct
66 Correct 129 ms 7720 KB Output is correct
67 Correct 88 ms 7588 KB Output is correct