Submission #112944

# Submission time Handle Problem Language Result Execution time Memory
112944 2019-05-22T17:52:49 Z nafis_shifat Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
54 ms 12544 KB
#include<bits/stdc++.h>
#define mx 30009
#define pii pair<int,int>
using namespace std;
int main()
{
    
    int n,m;
    cin>>n>>m;
    int b[m+1],p[m+1];
    int sp[n+1]={};
    vector<pii> edg[mx];
    set<int> mp[30009];
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&b[i],&p[i]);
        
        sp[b[i]]=p[i];
        
        
        
        
    }
    
    for(int i=0;i<m;i++)
    {
        int k=0;
        if(mp[b[i]].count(p[i]))continue;
        for(int j=b[i]+p[i];j<n;j+=p[i])
        {
            k++;
            if(sp[j]!=0 )
               edg[b[i]].push_back({j,k});
            if(mp[j].count(p[i]))break;
        }
        k=0;
        for(int j=b[i]-p[i];j>=0;j-=p[i])
        {
            k++;
            if(sp[j]!=0)
               edg[b[i]].push_back({j,k});
            if(mp[j].count(p[i]))break;
        }
        
        mp[b[i]].insert(p[i]);
    }
    
   
    
    
   
    int dist[mx+1];
    for(int i=0;i<=mx;i++)dist[i]=(int)2e9;
    priority_queue<pii,vector<pii>,greater<pii>> pq;

    
    pq.push({0,b[0]});
    dist[b[0]]=0;
    int vis[mx+1]={};
    
    while(!pq.empty())
    {
        int u=pq.top().second;
       
        pq.pop();
        if(u==b[1])
        {
            cout<<dist[u]<<endl;
            return 0;
        }
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<edg[u].size();i++)
        {
            
            if(dist[edg[u][i].first]>dist[u]+edg[u][i].second)
            {
                dist[edg[u][i].first]=dist[u]+edg[u][i].second;
               
                pq.push({dist[edg[u][i].first],edg[u][i].first});
            }
        }
    }
    
    cout<<-1<<endl;
    
    
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:73:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<edg[u].size();i++)
                     ~^~~~~~~~~~~~~~
skyscraper.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&b[i],&p[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2560 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 8 ms 2816 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Correct 5 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 5 ms 2816 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Correct 5 ms 2816 KB Output is correct
15 Correct 5 ms 2816 KB Output is correct
16 Correct 4 ms 2816 KB Output is correct
17 Correct 5 ms 2944 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 6 ms 3200 KB Output is correct
21 Correct 4 ms 2816 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 5 ms 2944 KB Output is correct
25 Correct 4 ms 2816 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 5 ms 3072 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 4 ms 2688 KB Output is correct
31 Correct 4 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 5 ms 2816 KB Output is correct
34 Correct 7 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 3 ms 2688 KB Output is correct
4 Correct 3 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 3 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 4 ms 2816 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Correct 4 ms 2816 KB Output is correct
17 Correct 5 ms 3072 KB Output is correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2760 KB Output is correct
20 Correct 5 ms 3200 KB Output is correct
21 Correct 4 ms 2816 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 4 ms 2688 KB Output is correct
24 Correct 5 ms 2816 KB Output is correct
25 Correct 5 ms 2816 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 5 ms 3072 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 3 ms 2688 KB Output is correct
33 Correct 4 ms 2816 KB Output is correct
34 Correct 5 ms 2816 KB Output is correct
35 Correct 20 ms 5248 KB Output is correct
36 Correct 6 ms 3072 KB Output is correct
37 Correct 22 ms 6144 KB Output is correct
38 Correct 26 ms 6400 KB Output is correct
39 Correct 26 ms 6392 KB Output is correct
40 Correct 25 ms 6392 KB Output is correct
41 Correct 26 ms 6392 KB Output is correct
42 Correct 8 ms 2944 KB Output is correct
43 Correct 8 ms 2944 KB Output is correct
44 Correct 10 ms 3456 KB Output is correct
45 Correct 20 ms 4608 KB Output is correct
46 Correct 20 ms 4736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 5 ms 2816 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Correct 4 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Correct 4 ms 2688 KB Output is correct
17 Correct 5 ms 2944 KB Output is correct
18 Correct 5 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 6 ms 3200 KB Output is correct
21 Correct 4 ms 2816 KB Output is correct
22 Correct 4 ms 2816 KB Output is correct
23 Correct 4 ms 2816 KB Output is correct
24 Correct 4 ms 2816 KB Output is correct
25 Correct 4 ms 2944 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 5 ms 3072 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 4 ms 2816 KB Output is correct
34 Correct 5 ms 2816 KB Output is correct
35 Correct 21 ms 5376 KB Output is correct
36 Correct 6 ms 3200 KB Output is correct
37 Correct 23 ms 6144 KB Output is correct
38 Correct 27 ms 6392 KB Output is correct
39 Correct 27 ms 6392 KB Output is correct
40 Correct 27 ms 6400 KB Output is correct
41 Correct 28 ms 6416 KB Output is correct
42 Correct 8 ms 2944 KB Output is correct
43 Correct 9 ms 2944 KB Output is correct
44 Correct 10 ms 3456 KB Output is correct
45 Correct 21 ms 4736 KB Output is correct
46 Correct 22 ms 4600 KB Output is correct
47 Correct 51 ms 12544 KB Output is correct
48 Correct 19 ms 5504 KB Output is correct
49 Correct 21 ms 4856 KB Output is correct
50 Correct 12 ms 4224 KB Output is correct
51 Correct 33 ms 7288 KB Output is correct
52 Correct 34 ms 7844 KB Output is correct
53 Correct 17 ms 5192 KB Output is correct
54 Correct 4 ms 2816 KB Output is correct
55 Correct 4 ms 2816 KB Output is correct
56 Correct 38 ms 11516 KB Output is correct
57 Correct 16 ms 4480 KB Output is correct
58 Correct 8 ms 3072 KB Output is correct
59 Correct 9 ms 3328 KB Output is correct
60 Correct 10 ms 3200 KB Output is correct
61 Correct 9 ms 3456 KB Output is correct
62 Correct 34 ms 9724 KB Output is correct
63 Correct 29 ms 4856 KB Output is correct
64 Correct 30 ms 4856 KB Output is correct
65 Correct 36 ms 4856 KB Output is correct
66 Correct 52 ms 4984 KB Output is correct
67 Correct 54 ms 5112 KB Output is correct