Submission #22018

# Submission time Handle Problem Language Result Execution time Memory
22018 2017-04-28T21:02:30 Z mohammad_kilani Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
389 ms 113584 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 30001;
bitset<N>vis[N];
int n,m;
vector< vector<int> > g;

int BFS(int s,int e){
    queue<pair<int,pair<int,int > > > q;
    q.push(make_pair(s,make_pair(g[s][0],0)));
    vis[s][0] = true;
    while(!q.empty()){
        int node = q.front().first;
        int jump = q.front().second.first;
        int cost = q.front().second.second;
        q.pop();
        if(node == e)
            return cost;
        int si = g[node].size();
        for(int i=0;i<=si;i++){
            int newjump;
            if(i == si)
                newjump = jump;
            else
                newjump = g[node][i];
            int newnode = node+newjump;
            if(newnode >= 0 && newnode < n && !vis[newnode][newjump]){
                vis[newnode][newjump] = true;
                q.push(make_pair(newnode,make_pair(newjump,cost+1)));
            }
            newnode = node-newjump;
            if(newnode >= 0 && newnode < n && !vis[newnode][newjump]){
                vis[newnode][newjump] = true;
                q.push(make_pair(newnode,make_pair(newjump,cost+1)));
            }
        }
    }
    return -1;
}

int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    g.resize(n+2);
    int s,e;
    for(int i=0;i<m;i++){
        int b,p;
        scanf("%d%d",&b,&p);
        g[b].push_back(p);
        if(i == 0){
            s = b;
        }
        if(i == 1)
            e = b;
    }
    cout << BFS(s,e);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:43:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
skyscraper.cpp:48:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&b,&p);
                            ^
skyscraper.cpp:56:20: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout << BFS(s,e);
                    ^
skyscraper.cpp:56:20: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 111948 KB Output is correct
2 Correct 0 ms 111948 KB Output is correct
3 Correct 0 ms 111948 KB Output is correct
4 Correct 0 ms 111948 KB Output is correct
5 Correct 0 ms 111948 KB Output is correct
6 Correct 0 ms 111948 KB Output is correct
7 Correct 0 ms 111948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 111948 KB Output is correct
2 Correct 0 ms 111948 KB Output is correct
3 Correct 0 ms 111948 KB Output is correct
4 Correct 0 ms 111948 KB Output is correct
5 Correct 0 ms 111948 KB Output is correct
6 Correct 0 ms 111948 KB Output is correct
7 Correct 0 ms 111948 KB Output is correct
8 Correct 0 ms 111948 KB Output is correct
9 Correct 0 ms 111948 KB Output is correct
10 Correct 0 ms 111948 KB Output is correct
11 Correct 0 ms 111948 KB Output is correct
12 Correct 0 ms 111948 KB Output is correct
13 Correct 0 ms 111948 KB Output is correct
14 Correct 0 ms 111948 KB Output is correct
15 Correct 0 ms 111948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 111948 KB Output is correct
2 Correct 0 ms 111948 KB Output is correct
3 Correct 0 ms 111948 KB Output is correct
4 Correct 0 ms 111948 KB Output is correct
5 Correct 0 ms 111948 KB Output is correct
6 Correct 0 ms 111948 KB Output is correct
7 Correct 0 ms 111948 KB Output is correct
8 Correct 0 ms 111948 KB Output is correct
9 Correct 0 ms 111948 KB Output is correct
10 Correct 0 ms 111948 KB Output is correct
11 Correct 0 ms 111948 KB Output is correct
12 Correct 0 ms 111948 KB Output is correct
13 Correct 0 ms 111948 KB Output is correct
14 Correct 0 ms 111948 KB Output is correct
15 Correct 0 ms 111948 KB Output is correct
16 Correct 0 ms 111948 KB Output is correct
17 Correct 0 ms 112080 KB Output is correct
18 Correct 0 ms 112080 KB Output is correct
19 Correct 0 ms 112080 KB Output is correct
20 Correct 0 ms 112080 KB Output is correct
21 Correct 0 ms 111948 KB Output is correct
22 Correct 0 ms 112080 KB Output is correct
23 Correct 0 ms 112080 KB Output is correct
24 Correct 6 ms 112080 KB Output is correct
25 Correct 0 ms 112080 KB Output is correct
26 Correct 0 ms 112080 KB Output is correct
27 Correct 3 ms 112080 KB Output is correct
28 Correct 3 ms 112080 KB Output is correct
29 Correct 6 ms 112080 KB Output is correct
30 Correct 0 ms 111948 KB Output is correct
31 Correct 3 ms 112080 KB Output is correct
32 Correct 3 ms 112080 KB Output is correct
33 Correct 3 ms 112080 KB Output is correct
34 Correct 3 ms 112080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 111948 KB Output is correct
2 Correct 0 ms 111948 KB Output is correct
3 Correct 0 ms 111948 KB Output is correct
4 Correct 0 ms 111948 KB Output is correct
5 Correct 0 ms 111948 KB Output is correct
6 Correct 0 ms 111948 KB Output is correct
7 Correct 0 ms 111948 KB Output is correct
8 Correct 0 ms 111948 KB Output is correct
9 Correct 0 ms 111948 KB Output is correct
10 Correct 0 ms 111948 KB Output is correct
11 Correct 0 ms 111948 KB Output is correct
12 Correct 0 ms 111948 KB Output is correct
13 Correct 0 ms 111948 KB Output is correct
14 Correct 0 ms 111948 KB Output is correct
15 Correct 0 ms 111948 KB Output is correct
16 Correct 0 ms 111948 KB Output is correct
17 Correct 3 ms 112080 KB Output is correct
18 Correct 0 ms 112080 KB Output is correct
19 Correct 0 ms 112080 KB Output is correct
20 Correct 6 ms 112080 KB Output is correct
21 Correct 0 ms 111948 KB Output is correct
22 Correct 0 ms 112080 KB Output is correct
23 Correct 3 ms 112080 KB Output is correct
24 Correct 0 ms 112080 KB Output is correct
25 Correct 0 ms 112080 KB Output is correct
26 Correct 0 ms 112080 KB Output is correct
27 Correct 0 ms 112080 KB Output is correct
28 Correct 3 ms 112080 KB Output is correct
29 Correct 6 ms 112080 KB Output is correct
30 Correct 0 ms 111948 KB Output is correct
31 Correct 3 ms 112080 KB Output is correct
32 Correct 0 ms 112080 KB Output is correct
33 Correct 3 ms 112080 KB Output is correct
34 Correct 6 ms 112080 KB Output is correct
35 Correct 13 ms 112484 KB Output is correct
36 Correct 0 ms 112080 KB Output is correct
37 Correct 6 ms 112344 KB Output is correct
38 Correct 13 ms 112608 KB Output is correct
39 Correct 6 ms 112344 KB Output is correct
40 Correct 9 ms 112344 KB Output is correct
41 Correct 13 ms 112344 KB Output is correct
42 Correct 6 ms 112212 KB Output is correct
43 Correct 9 ms 112212 KB Output is correct
44 Correct 9 ms 112212 KB Output is correct
45 Correct 49 ms 112872 KB Output is correct
46 Correct 43 ms 112872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 111948 KB Output is correct
2 Correct 0 ms 111948 KB Output is correct
3 Correct 0 ms 111948 KB Output is correct
4 Correct 0 ms 111948 KB Output is correct
5 Correct 0 ms 111948 KB Output is correct
6 Correct 0 ms 111948 KB Output is correct
7 Correct 0 ms 111948 KB Output is correct
8 Correct 0 ms 111948 KB Output is correct
9 Correct 0 ms 111948 KB Output is correct
10 Correct 0 ms 111948 KB Output is correct
11 Correct 0 ms 111948 KB Output is correct
12 Correct 0 ms 111948 KB Output is correct
13 Correct 0 ms 111948 KB Output is correct
14 Correct 0 ms 111948 KB Output is correct
15 Correct 0 ms 111948 KB Output is correct
16 Correct 0 ms 111948 KB Output is correct
17 Correct 0 ms 112080 KB Output is correct
18 Correct 0 ms 112080 KB Output is correct
19 Correct 0 ms 112080 KB Output is correct
20 Correct 3 ms 112080 KB Output is correct
21 Correct 0 ms 111948 KB Output is correct
22 Correct 0 ms 112080 KB Output is correct
23 Correct 0 ms 112080 KB Output is correct
24 Correct 0 ms 112080 KB Output is correct
25 Correct 0 ms 112080 KB Output is correct
26 Correct 3 ms 112080 KB Output is correct
27 Correct 3 ms 112080 KB Output is correct
28 Correct 3 ms 112080 KB Output is correct
29 Correct 0 ms 112080 KB Output is correct
30 Correct 0 ms 111948 KB Output is correct
31 Correct 0 ms 112080 KB Output is correct
32 Correct 3 ms 112080 KB Output is correct
33 Correct 3 ms 112080 KB Output is correct
34 Correct 3 ms 112080 KB Output is correct
35 Correct 6 ms 112484 KB Output is correct
36 Correct 0 ms 112080 KB Output is correct
37 Correct 6 ms 112344 KB Output is correct
38 Correct 9 ms 112608 KB Output is correct
39 Correct 6 ms 112344 KB Output is correct
40 Correct 9 ms 112344 KB Output is correct
41 Correct 6 ms 112344 KB Output is correct
42 Correct 3 ms 112212 KB Output is correct
43 Correct 6 ms 112212 KB Output is correct
44 Correct 9 ms 112212 KB Output is correct
45 Correct 49 ms 112872 KB Output is correct
46 Correct 46 ms 112872 KB Output is correct
47 Correct 6 ms 112636 KB Output is correct
48 Correct 6 ms 113024 KB Output is correct
49 Correct 6 ms 113072 KB Output is correct
50 Correct 6 ms 113000 KB Output is correct
51 Correct 33 ms 113312 KB Output is correct
52 Correct 36 ms 113444 KB Output is correct
53 Correct 13 ms 113312 KB Output is correct
54 Correct 6 ms 112652 KB Output is correct
55 Correct 13 ms 112652 KB Output is correct
56 Correct 26 ms 113576 KB Output is correct
57 Correct 3 ms 112784 KB Output is correct
58 Correct 39 ms 112924 KB Output is correct
59 Correct 33 ms 112924 KB Output is correct
60 Correct 36 ms 112932 KB Output is correct
61 Correct 29 ms 112940 KB Output is correct
62 Correct 99 ms 113576 KB Output is correct
63 Correct 166 ms 113180 KB Output is correct
64 Correct 136 ms 113048 KB Output is correct
65 Correct 229 ms 113284 KB Output is correct
66 Correct 389 ms 113584 KB Output is correct
67 Correct 206 ms 113584 KB Output is correct