Submission #22003

#TimeUsernameProblemLanguageResultExecution timeMemory
22003mohammad_kilaniJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
0 ms21572 KiB
#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][g[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]; if(node-jump >= 0 && !vis[node-jump][jump]){ vis[node-jump][jump] = true; cost[node-jump][jump] = cost[node][jump] + 1; q.push(make_pair(node-jump,jump)); } if(node+jump < n && !vis[node+jump][jump]){ vis[node+jump][jump] = true; cost[node+jump][jump] = cost[node][jump] + 1; q.push(make_pair(node+jump,jump)); } int si = g[node].size(); for(int i=0;i<si;i++){ int newjump = g[node][i]; if(node-newjump >= 0 && !vis[node-newjump][newjump]){ vis[node-newjump][newjump] = true; cost[node-newjump][newjump] = cost[node][jump] + 1; q.push(make_pair(node-newjump,newjump)); } if(node+newjump < n && !vis[node+newjump][newjump]){ vis[node+newjump][newjump] = true; cost[node+newjump][newjump] = cost[node][jump] + 1; q.push(make_pair(node+newjump,newjump)); } } } return 0; } 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 (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50: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:55: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:63:20: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout << BFS(s,e);
                    ^
skyscraper.cpp:63:20: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...