Submission #31724

#TimeUsernameProblemLanguageResultExecution timeMemory
31724top34051Jakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
333 ms17864 KiB
#include<bits/stdc++.h> using namespace std; #define inf 1e9 struct node { int x,val; node(int _x = 0,int _val = 0) { x = _x; val = _val; } bool operator < (node a) const { return a.val<val; } }; int n,m,st,ft; int mem[2005]; int from[2005][2005]; priority_queue<node> heap; main() { int i,j,x,y,pos,val; scanf("%d%d",&n,&m); for(i=0;i<n;i++) for(j=0;j<n;j++) from[i][j] = inf; for(i=0;i<m;i++) { scanf("%d%d",&pos,&val); if(i==0) st = pos; if(i==1) ft = pos; for(x=0;x<n;x++) if(abs(pos-x)%val==0) from[pos][x] = min(from[pos][x],abs(pos-x)/val); } for(i=0;i<n;i++) mem[i] = inf; mem[st] = 0; heap.push(node(st,0)); while(!heap.empty()) { x = heap.top().x; heap.pop(); for(y=0;y<n;y++) { val = from[x][y]; if(mem[y] > mem[x] + val) { mem[y] = mem[x] + val; heap.push(node(y,mem[y])); } } } if(mem[ft]==inf) printf("-1"); else printf("%d",mem[ft]); }

Compilation message (stderr)

skyscraper.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:19: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:22:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&pos,&val);
                                ^
#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...