Submission #244718

#TimeUsernameProblemLanguageResultExecution timeMemory
244718uacoder123Jakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
251 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define mp(i,a) make_pair(i,a) #define pb(a) push_back(a) #define bit(x,b) (x&(1LL<<b)) typedef int lli; typedef pair <lli,lli> ii; typedef pair <lli,ii> iii; typedef vector <lli> vi; vector<int> al[5220000]; lli dis[5220000],n; set<ii> s; map<ii,int> ma; lli dij(lli so,lli t) { for(lli i=0;i<5220000;++i) dis[i]=1000000000; s.insert(mp(0,so)); dis[so]=0; while(s.size()!=0) { ii v=(*s.begin()); s.erase(s.begin()); dis[v.S]=v.F; for(lli i=0;i<al[v.S].size();++i) { if(al[v.S][i]%100000+v.F<dis[al[v.S][i]/100000]) { s.erase(mp(dis[al[v.S][i]/100000],al[v.S][i]/100000)); dis[al[v.S][i]/100000]=al[v.S][i]%100000+v.F; s.insert(mp(dis[al[v.S][i]/100000],al[v.S][i]/100000)); } } } if(dis[t]==1000000000) return(-1); return(dis[t]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli test=1; for(;test>0;--test) { lli m,rn, from, to; cin>>n>>m; rn=sqrt(n)+1; for(lli i=0;i<m;++i) { lli f,se; cin>>f>>se; if(i==0) from = f; if(i==1) to = f; if(se<rn) { al[rn*n+f].pb(((se)*n+f)*100000+0); al[se*n+f].pb((rn*n+f)*100000+0); if(se==0||ma.find(mp(f%se,se))!=ma.end()) continue; ma[mp(f%se,se)]=1; for(lli j=f%se;j<n;j+=se) { if(j+se<n) { al[se*n+j].pb((se*n+j+se)*100000+1); al[se*n+j+se].pb((se*n+j)*100000+1); } if(j+se<n) al[se*n+j].pb((rn*n+j+se)*100000+1); if(j-se>=0) al[se*n+j].pb((rn*n+j-se)*100000+1); } } if(se>=rn) { lli p=f+se; while(p<n) { al[rn*n+f].pb((rn*n+p)*100000+(p-f)/se); p+=se; } p=f-se; while(p>=0) { al[rn*n+f].pb((rn*n+p)*100000+(f-p)/se); p-=se; } } } cout<<dij(rn*n+from,rn*n+to)<<endl; } return(0); }

Compilation message (stderr)

skyscraper.cpp: In function 'lli dij(lli, lli)':
skyscraper.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(lli i=0;i<al[v.S].size();++i)
                 ~^~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:99:32: warning: 'to' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout<<dij(rn*n+from,rn*n+to)<<endl;
                                ^
skyscraper.cpp:99:32: warning: 'from' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...