# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22004 | 2017-04-28T19:19:13 Z | mohammad_kilani | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 0 ms | 21572 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][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]; int si = g[node].size(); for(int i=0;i<=si;i++){ int newjump; if(i == si) newjump = jump; else newjump = g[node][i]; vis[node][newjump] = true; 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 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
# | 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 | Incorrect | 0 ms | 21572 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 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 | Incorrect | 0 ms | 21572 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 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 | Incorrect | 0 ms | 21572 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 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 | Incorrect | 0 ms | 21572 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 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 | Incorrect | 0 ms | 21572 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |