Submission #244672

#TimeUsernameProblemLanguageResultExecution timeMemory
244672uacoder123Jakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
103 ms149240 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<ii> al[5430000]; lli dis[5430000]; set<ii> s; lli dij(lli so,lli t) { for(lli i=0;i<5430000;++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].S+v.F<dis[al[v.S][i].F]) { s.erase(mp(dis[al[v.S][i].F],al[v.S][i].F)); dis[al[v.S][i].F]=al[v.S][i].S+v.F; s.insert(mp(dis[al[v.S][i].F],al[v.S][i].F)); } } } 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 n,m,rn; cin>>n>>m; rn=sqrt(n)+1; ii dg[m]; map<ii,int> ma; for(lli i=0;i<m;++i) { lli f,se; cin>>f>>se; dg[i]=mp(f,se); if(se<rn) { al[rn*n+f].pb(mp((se)*n+f,0)); al[se*n+f].pb(mp(rn*n+f,0)); lli p=f+se; if(ma.find(mp(f%se,se))!=ma.end()) break; ma[mp(f%se,se)]=1; while(p<n) { al[se*n+p-se].pb(mp(se*n+p,1)); al[se*n+p].pb(mp(se*n+p-se,1)); al[se*n+p-se].pb(mp(rn*n+p,1)); al[se*n+p].pb(mp(rn*n+p-se,1)); p+=se; } p=f-se; while(p>=0) { al[se*n+p+se].pb(mp(se*n+p,1)); al[se*n+p].pb(mp(se*n+p+se,1)); al[se*n+p].pb(mp(rn*n+p+se,1)); al[se*n+p+se].pb(mp(rn*n+p,1)); p-=se; } } if(se>=rn) { lli p=f+se; while(p<n) { al[rn*n+f].pb(mp(rn*n+p,(p-f)/se)); p+=se; } p=f-se; while(p>=0) { al[rn*n+f].pb(mp(rn*n+p,(f-p)/se)); p-=se; } } } cout<<dij(rn*n+dg[0].F,rn*n+dg[1].F)<<endl; } return(0); }

Compilation message (stderr)

skyscraper.cpp: In function 'lli dij(lli, lli)':
skyscraper.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(lli i=0;i<al[v.S].size();++i)
                 ~^~~~~~~~~~~~~~~
#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...