제출 #23564

#제출 시각아이디문제언어결과실행 시간메모리
23564samir_droubiJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
373 ms112020 KiB
#include <bits/stdc++.h> using namespace std; int n,m; const int mxn=(1e5)+5; vector<pair<int,int> >gr[mxn]; set<int>a[mxn]; set<pair<int,int> >s; int st,en; int dis[mxn]; set<pair<int,int> >::iterator it; set<int>::iterator itt; void dijk() { for(int i=0;i<mxn;++i)dis[i]=(1e9); dis[st]=0; s.insert({0,st}); while(!s.empty()) { it=s.begin(); int v=it->second; int d=it->first; s.erase(it); for(int i=0;i<gr[v].size();++i) { int u=gr[v][i].first; int w=gr[v][i].second; if(d+w<dis[u]) { dis[u]=d+w; s.insert({d+w,u}); } } } } int main() { scanf("%d%d",&n,&m); for(int i=0;i<m;++i) { int b,p; scanf("%d%d",&b,&p); a[b].insert(p); if(i==0)st=b; if(i==1)en=b; } for(int i=0;i<n;++i) { itt=a[i].begin(); for(itt;itt!=a[i].end();++itt) { int p=*itt; for(int j=1;i+(j*p)<n;++j) { int cur=i+(j*p); gr[i].push_back({cur,j}); if(a[cur].count(p))break; } } } for(int i=n-1;i>=0;--i) { itt=a[i].begin(); for(itt;itt!=a[i].end();++itt) { int p=*itt; for(int j=1;i-(j*p)>=0;++j) { int cur=i-(j*p); gr[i].push_back({cur,j}); if(a[cur].count(p))break; } } } dijk(); if(dis[en]==(1e9))dis[en]=-1; printf("%d\n",dis[en]); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'void dijk()':
skyscraper.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<gr[v].size();++i)
                ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:10: warning: statement has no effect [-Wunused-value]
   for(itt;itt!=a[i].end();++itt)
          ^
skyscraper.cpp:65:10: warning: statement has no effect [-Wunused-value]
   for(itt;itt!=a[i].end();++itt)
          ^
skyscraper.cpp:37:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
skyscraper.cpp:41:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&b,&p);
                      ^
#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...