Submission #22005

# Submission time Handle Problem Language Result Execution time Memory
22005 2017-04-28T19:39:43 Z mohammad_kilani Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
49 ms 22368 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2001;
bool vis[N][N];
int cost[N][N];
int n,m;
vector<vector<int> > g;

int BFS(int s,int e){
    queue<pair<int,int> > q;
    q.push(make_pair(s,g[s][0]));
    vis[s][0] = true;
    while(!q.empty()){
        int node = q.front().first;
        int jump = q.front().second;
        q.pop();
        if(node == e)
            return cost[node][jump];
        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;
                cost[newnode][newjump] = cost[node][jump]+1;
                q.push(make_pair(newnode,newjump));
            }
            newnode = node-newjump;
            if(newnode >= 0 && newnode < n && !vis[newnode][newjump]){
                vis[newnode][newjump] = true;
                cost[newnode][newjump] = cost[node][jump]+1;
                q.push(make_pair(newnode,newjump));
            }
        }
    }
    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:45: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:50: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:58:20: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout << BFS(s,e);
                    ^
skyscraper.cpp:58:20: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21572 KB Output is correct
2 Correct 0 ms 21572 KB Output is correct
3 Correct 0 ms 21572 KB Output is correct
4 Correct 0 ms 21572 KB Output is correct
5 Correct 0 ms 21572 KB Output is correct
6 Correct 0 ms 21572 KB Output is correct
7 Correct 0 ms 21572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21572 KB Output is correct
2 Correct 0 ms 21572 KB Output is correct
3 Correct 0 ms 21572 KB Output is correct
4 Correct 0 ms 21572 KB Output is correct
5 Correct 0 ms 21572 KB Output is correct
6 Correct 0 ms 21572 KB Output is correct
7 Correct 0 ms 21572 KB Output is correct
8 Correct 0 ms 21572 KB Output is correct
9 Correct 0 ms 21572 KB Output is correct
10 Correct 0 ms 21572 KB Output is correct
11 Correct 0 ms 21572 KB Output is correct
12 Correct 0 ms 21572 KB Output is correct
13 Correct 0 ms 21572 KB Output is correct
14 Correct 0 ms 21572 KB Output is correct
15 Correct 0 ms 21572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21572 KB Output is correct
2 Correct 0 ms 21572 KB Output is correct
3 Correct 0 ms 21572 KB Output is correct
4 Correct 0 ms 21572 KB Output is correct
5 Correct 0 ms 21572 KB Output is correct
6 Correct 0 ms 21572 KB Output is correct
7 Correct 0 ms 21572 KB Output is correct
8 Correct 0 ms 21572 KB Output is correct
9 Correct 0 ms 21572 KB Output is correct
10 Correct 0 ms 21572 KB Output is correct
11 Correct 0 ms 21572 KB Output is correct
12 Correct 0 ms 21572 KB Output is correct
13 Correct 0 ms 21572 KB Output is correct
14 Correct 0 ms 21572 KB Output is correct
15 Correct 0 ms 21572 KB Output is correct
16 Correct 0 ms 21572 KB Output is correct
17 Correct 3 ms 21704 KB Output is correct
18 Correct 0 ms 21704 KB Output is correct
19 Correct 0 ms 21704 KB Output is correct
20 Correct 0 ms 21704 KB Output is correct
21 Correct 0 ms 21572 KB Output is correct
22 Correct 0 ms 21704 KB Output is correct
23 Correct 3 ms 21704 KB Output is correct
24 Correct 3 ms 21704 KB Output is correct
25 Correct 0 ms 21704 KB Output is correct
26 Correct 3 ms 21704 KB Output is correct
27 Correct 6 ms 21704 KB Output is correct
28 Correct 3 ms 21704 KB Output is correct
29 Correct 3 ms 21704 KB Output is correct
30 Correct 0 ms 21572 KB Output is correct
31 Correct 3 ms 21704 KB Output is correct
32 Correct 0 ms 21704 KB Output is correct
33 Correct 3 ms 21704 KB Output is correct
34 Correct 6 ms 21704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21572 KB Output is correct
2 Correct 0 ms 21572 KB Output is correct
3 Correct 0 ms 21572 KB Output is correct
4 Correct 0 ms 21572 KB Output is correct
5 Correct 0 ms 21572 KB Output is correct
6 Correct 0 ms 21572 KB Output is correct
7 Correct 0 ms 21572 KB Output is correct
8 Correct 0 ms 21572 KB Output is correct
9 Correct 0 ms 21572 KB Output is correct
10 Correct 0 ms 21572 KB Output is correct
11 Correct 0 ms 21572 KB Output is correct
12 Correct 0 ms 21572 KB Output is correct
13 Correct 0 ms 21572 KB Output is correct
14 Correct 0 ms 21572 KB Output is correct
15 Correct 0 ms 21572 KB Output is correct
16 Correct 0 ms 21572 KB Output is correct
17 Correct 0 ms 21704 KB Output is correct
18 Correct 0 ms 21704 KB Output is correct
19 Correct 0 ms 21704 KB Output is correct
20 Correct 0 ms 21704 KB Output is correct
21 Correct 0 ms 21572 KB Output is correct
22 Correct 0 ms 21704 KB Output is correct
23 Correct 0 ms 21704 KB Output is correct
24 Correct 3 ms 21704 KB Output is correct
25 Correct 3 ms 21704 KB Output is correct
26 Correct 3 ms 21704 KB Output is correct
27 Correct 0 ms 21704 KB Output is correct
28 Correct 6 ms 21704 KB Output is correct
29 Correct 6 ms 21704 KB Output is correct
30 Correct 0 ms 21572 KB Output is correct
31 Correct 0 ms 21704 KB Output is correct
32 Correct 0 ms 21704 KB Output is correct
33 Correct 3 ms 21704 KB Output is correct
34 Correct 3 ms 21704 KB Output is correct
35 Correct 19 ms 21968 KB Output is correct
36 Correct 3 ms 21704 KB Output is correct
37 Correct 13 ms 21968 KB Output is correct
38 Correct 16 ms 22100 KB Output is correct
39 Correct 6 ms 21968 KB Output is correct
40 Correct 16 ms 21968 KB Output is correct
41 Correct 16 ms 21968 KB Output is correct
42 Correct 6 ms 21836 KB Output is correct
43 Correct 9 ms 21836 KB Output is correct
44 Correct 6 ms 21836 KB Output is correct
45 Correct 49 ms 22368 KB Output is correct
46 Correct 33 ms 22368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 21572 KB Output is correct
2 Correct 0 ms 21572 KB Output is correct
3 Correct 0 ms 21572 KB Output is correct
4 Correct 0 ms 21572 KB Output is correct
5 Correct 0 ms 21572 KB Output is correct
6 Correct 0 ms 21572 KB Output is correct
7 Correct 0 ms 21572 KB Output is correct
8 Correct 0 ms 21572 KB Output is correct
9 Correct 0 ms 21572 KB Output is correct
10 Correct 0 ms 21572 KB Output is correct
11 Correct 0 ms 21572 KB Output is correct
12 Correct 0 ms 21572 KB Output is correct
13 Correct 0 ms 21572 KB Output is correct
14 Correct 0 ms 21572 KB Output is correct
15 Correct 0 ms 21572 KB Output is correct
16 Correct 0 ms 21572 KB Output is correct
17 Correct 0 ms 21704 KB Output is correct
18 Correct 0 ms 21704 KB Output is correct
19 Correct 0 ms 21704 KB Output is correct
20 Correct 0 ms 21704 KB Output is correct
21 Correct 0 ms 21572 KB Output is correct
22 Correct 0 ms 21704 KB Output is correct
23 Correct 0 ms 21704 KB Output is correct
24 Correct 0 ms 21704 KB Output is correct
25 Correct 0 ms 21704 KB Output is correct
26 Correct 3 ms 21704 KB Output is correct
27 Correct 0 ms 21704 KB Output is correct
28 Correct 0 ms 21704 KB Output is correct
29 Correct 3 ms 21704 KB Output is correct
30 Correct 0 ms 21572 KB Output is correct
31 Correct 3 ms 21704 KB Output is correct
32 Correct 3 ms 21704 KB Output is correct
33 Correct 13 ms 21704 KB Output is correct
34 Correct 6 ms 21704 KB Output is correct
35 Correct 19 ms 21968 KB Output is correct
36 Correct 3 ms 21704 KB Output is correct
37 Correct 6 ms 21968 KB Output is correct
38 Correct 9 ms 22100 KB Output is correct
39 Correct 9 ms 21968 KB Output is correct
40 Correct 9 ms 21968 KB Output is correct
41 Correct 9 ms 21968 KB Output is correct
42 Correct 9 ms 21836 KB Output is correct
43 Correct 13 ms 21836 KB Output is correct
44 Correct 6 ms 21836 KB Output is correct
45 Correct 43 ms 22368 KB Output is correct
46 Correct 33 ms 22368 KB Output is correct
47 Runtime error 6 ms 22260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Halted 0 ms 0 KB -