Submission #31723

#TimeUsernameProblemLanguageResultExecution timeMemory
31723top34051Jakarta Skyscrapers (APIO15_skyscraper)C++14
36 / 100
339 ms262144 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];
vector<pair<int,int> > from[2005];
priority_queue<node> heap;
main() {
    int i,x,y,pos,val;
    scanf("%d%d",&n,&m);
    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].push_back({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(i=0;i<from[x].size();i++) {
            y = from[x][i].first; val = from[x][i].second;
            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:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<from[x].size();i++) {
                  ^
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:21: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...