Submission #146041

# Submission time Handle Problem Language Result Execution time Memory
146041 2019-08-21T16:38:12 Z str0ct Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
137 ms 5732 KB
#include<bits/stdc++.h>
using namespace std;
using pii=pair <int,int>;
int vis[30303];
int N,M;
pair <int,int> ipt[30303];
vector <int> V[30303];
priority_queue<pii,vector<pii>,greater<pii> > pq;
void dijkstra(){
    pq.push({0,ipt[0].first});
    vis[ipt[0].first]=0;
    while(!pq.empty()){
        int a=pq.top().first,b=pq.top().second;
        pq.pop();
        if(a<=vis[b]){
            for(auto i:V[b]){
                for(int k=1;b+i*k<N;k++){
                        if(vis[b+i*k]>a+k){
                            pq.push({a+k,b+i*k});
                            vis[b+i*k]=a+k;
                        }
                        auto it=lower_bound(V[b+i*k].begin(),V[b+i*k].end(),i);
                        if(it!=V[b+i*k].end()&&*it==i)break;
                }
                for(int k=1;b-i*k>=0;k++){
                        if(vis[b-i*k]>a+k){
                            pq.push({a+k,b-i*k});
                            vis[b-i*k]=a+k;
                        }
                        auto it=lower_bound(V[b-i*k].begin(),V[b-i*k].end(),i);
                        if(it!=V[b-i*k].end()&&*it==i)break;
                }
            }
        }
    }
}

int main(){
    fill(vis,vis+30303,1010101010);
    scanf("%d%d",&N,&M);
    for(int i=0;i<M;i++){
        scanf("%d%d",&ipt[i].first,&ipt[i].second);
        V[ipt[i].first].push_back(ipt[i].second);
    }
    for(int i=0;i<30003;i++){
        sort(V[i].begin(),V[i].end());
        V[i].erase(unique(V[i].begin(),V[i].end()),V[i].end());
    }
    dijkstra();
    if(vis[ipt[1].first]!=1010101010)printf("%d",vis[ipt[1].first]);
    else puts("-1");
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&ipt[i].first,&ipt[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1204 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1148 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1148 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1272 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 4 ms 1272 KB Output is correct
26 Correct 3 ms 1144 KB Output is correct
27 Correct 3 ms 1272 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 5 ms 1400 KB Output is correct
30 Correct 4 ms 1272 KB Output is correct
31 Correct 4 ms 1272 KB Output is correct
32 Correct 4 ms 1272 KB Output is correct
33 Correct 7 ms 1528 KB Output is correct
34 Correct 7 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1148 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1272 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 4 ms 1272 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 4 ms 1272 KB Output is correct
26 Correct 3 ms 1272 KB Output is correct
27 Correct 3 ms 1144 KB Output is correct
28 Correct 3 ms 1272 KB Output is correct
29 Correct 5 ms 1400 KB Output is correct
30 Correct 3 ms 1272 KB Output is correct
31 Correct 4 ms 1272 KB Output is correct
32 Correct 4 ms 1272 KB Output is correct
33 Correct 7 ms 1656 KB Output is correct
34 Correct 7 ms 1656 KB Output is correct
35 Correct 13 ms 1656 KB Output is correct
36 Correct 5 ms 1272 KB Output is correct
37 Correct 13 ms 1528 KB Output is correct
38 Correct 16 ms 1656 KB Output is correct
39 Correct 16 ms 1656 KB Output is correct
40 Correct 17 ms 1784 KB Output is correct
41 Correct 17 ms 1916 KB Output is correct
42 Correct 9 ms 1656 KB Output is correct
43 Correct 9 ms 1656 KB Output is correct
44 Correct 9 ms 1656 KB Output is correct
45 Correct 15 ms 1912 KB Output is correct
46 Correct 16 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 2 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1148 KB Output is correct
8 Correct 3 ms 1148 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1272 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1272 KB Output is correct
23 Correct 4 ms 1144 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 4 ms 1272 KB Output is correct
26 Correct 3 ms 1144 KB Output is correct
27 Correct 3 ms 1144 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 5 ms 1372 KB Output is correct
30 Correct 4 ms 1400 KB Output is correct
31 Correct 4 ms 1272 KB Output is correct
32 Correct 4 ms 1272 KB Output is correct
33 Correct 7 ms 1656 KB Output is correct
34 Correct 7 ms 1528 KB Output is correct
35 Correct 13 ms 1528 KB Output is correct
36 Correct 5 ms 1272 KB Output is correct
37 Correct 13 ms 1528 KB Output is correct
38 Correct 16 ms 1728 KB Output is correct
39 Correct 16 ms 1656 KB Output is correct
40 Correct 16 ms 1756 KB Output is correct
41 Correct 16 ms 1788 KB Output is correct
42 Correct 9 ms 1656 KB Output is correct
43 Correct 9 ms 1656 KB Output is correct
44 Correct 9 ms 1656 KB Output is correct
45 Correct 15 ms 1912 KB Output is correct
46 Correct 15 ms 1912 KB Output is correct
47 Correct 35 ms 2296 KB Output is correct
48 Correct 11 ms 1784 KB Output is correct
49 Correct 11 ms 1784 KB Output is correct
50 Correct 8 ms 1656 KB Output is correct
51 Correct 38 ms 2680 KB Output is correct
52 Correct 40 ms 2680 KB Output is correct
53 Correct 23 ms 2552 KB Output is correct
54 Correct 5 ms 1400 KB Output is correct
55 Correct 5 ms 1400 KB Output is correct
56 Correct 14 ms 2296 KB Output is correct
57 Correct 30 ms 1908 KB Output is correct
58 Correct 11 ms 1784 KB Output is correct
59 Correct 12 ms 1784 KB Output is correct
60 Correct 13 ms 1784 KB Output is correct
61 Correct 13 ms 1784 KB Output is correct
62 Correct 19 ms 2296 KB Output is correct
63 Correct 51 ms 3824 KB Output is correct
64 Correct 61 ms 3824 KB Output is correct
65 Correct 67 ms 3816 KB Output is correct
66 Correct 136 ms 5732 KB Output is correct
67 Correct 137 ms 5732 KB Output is correct