Submission #398267

#TimeUsernameProblemLanguageResultExecution timeMemory
398267juggernautJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
955 ms5052 KiB
#include<bits/stdc++.h> #define f first #define s second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif typedef pair<int,int> dat; dat a[30010]; int st[30010],D[30010]; priority_queue<dat,vector<dat>,greater<dat> > q; int main(){ int i,j,n,m,s,e,d; scanf("%d%d",&n,&m); for(i=0;i<m;++i)scanf("%d%d",&a[i].f,&a[i].s); s=a[0].f,e=a[1].f; sort(a,a+m); st[a[0].f]=0; for(i=1;i<m;++i)if(a[i].f!=a[i-1].f)st[a[i].f]=i; for(i=0;i<n;++i)D[i]=2e9; D[s]=0; q.push({0,s}); while(!q.empty()){ dat p=q.top(); q.pop(); if(D[p.s]!=p.f)continue; for(i=st[p.s];a[i].f==p.s&&i<m;++i){ d=p.f; for(j=p.s+a[i].s;j<n;j+=a[i].s)if(D[j]>++d)q.push({D[j]=d,j}); d=p.f; for(j=p.s-a[i].s;j>=0;j-=a[i].s)if(D[j]>++d)q.push({D[j]=d,j}); } } printf("%d",D[e]<2e9?D[e]:-1); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void usaco(std::string)':
skyscraper.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:27:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     for(i=0;i<m;++i)scanf("%d%d",&a[i].f,&a[i].s);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...