Submission #124115

#TimeUsernameProblemLanguageResultExecution timeMemory
124115naderjemelJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
309 ms32380 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define INF 1e9 typedef long long ll; typedef vector<int> vi; typedef pair<int,int> ii; typedef vector<pair<int,int> > vii; int n,m; //vector<vi> ns; //int jm[30005]; int dis[2005][2005]; int dist[2005]; int main(){ //printf("here\n"); scanf("%d%d",&n,&m); for(int i=0;i<n;i++) for(int j=0;j<n;j++) dis[i][j]=1e9; for(int i=0;i<n;i++) dist[i]=1e9; //ns.assign(n+2,vi()); int n1; int nf; for(int i=0;i<m;i++){ int x,y; scanf("%d%d",&x,&y); if(!i) n1=x; if(i==1) nf=x; //ns[x].pb(i); //jm[i]=y; for(int j=0;j<n;j++){ if(abs(x-j)%y==0){ dis[x][j]=min(dis[x][j],abs(x-j)/y); } } } //for(int i=0;i<n;i++) printf("%d ", dis[n1][i]); printf("\n"); priority_queue<ii,vector<ii>,greater<ii> > pq; pq.push(mp(0,n1)); while(!pq.empty()){ int u=pq.top().se; int d=pq.top().fi; pq.pop(); if(d>dist[u]) continue; if(u==nf){ printf("%d\n", d); return 0; } for(int i=0;i<n;i++){ if(u==i) continue; if(dis[u][i]==1e9) continue; if(dis[u][i]+d<dist[i]){ dist[i]=dis[u][i]+d; pq.push(mp(dist[i],i)); } } } //printf("%d %d\n", n1,nf); printf("-1\n"); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:41:12: warning: 'n1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  pq.push(mp(0,n1));
            ^
skyscraper.cpp:47:3: warning: 'nf' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(u==nf){
   ^~
#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...