Submission #42593

#TimeUsernameProblemLanguageResultExecution timeMemory
42593repeatingJakarta Skyscrapers (APIO15_skyscraper)C++11
57 / 100
1066 ms21680 KiB
#include <bits/stdc++.h> #define F first #define S second #define P push #define pb push_back #define MEM(dp,i) memset(dp,i,sizeof(dp)) #define W while #define R return #define C continue #define SI size() #define ll long long #define ld long double #define pll pair<ll,ll> #define pii pair<short,short> #define SF(x) scanf("%Id",&x) #define SF2(x,y) scanf("%Id%Id",&x,&y) #define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z) #define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o) #define all(v) v.begin(),v.end() using namespace std; const long long INF = 1e9+1; const long long MOD = 1e9+7; const int MX=200015; int sq=200; int n,m; bool vis[30005][280]; vector<short int> v[30005]; int f,t; priority_queue< pair<int,pii> , vector< pair<int,pii> > , greater< pair<int,pii> > > pq; void dijkstra(){ pq.P({0,{f,0}}); int j,ver,val; W(!pq.empty()){ val=pq.top().F; ver=pq.top().S.F; j=pq.top().S.S; pq.pop(); if(vis[ver][j])continue; vis[ver][j]=1; // cout<<ver<<" "<<j<<" "<<val<<endl; if(ver==t){ cout<<val; exit(0); } if(j==0){ for(auto i : v[ver]){ if(i<sq){ if(vis[ver][i]==0) pq.P({val,{ver,i}}); } else{ short o=1; for(int j=ver-i;j>=0;j-=i){ if(vis[j][0]==0) pq.P({o+val,{j,0}}); o++; } o=1; for(int j=ver+i;j<n;j+=i){ if(vis[j][0]==0) pq.P({o+val,{j,0}}); o++; } } } } else{ if(ver-j>=0){ if(vis[ver-j][j]==0) pq.P({val+1,{ver-j,j}}); if(vis[ver-j][0]==0) pq.P({val+1,{ver-j,0}}); } if(ver+j<n){ if(vis[ver+j][j]==0) pq.P({val+1,{ver+j,j}}); if(vis[ver+j][0]==0) pq.P({val+1,{ver+j,0}}); } } } } int main(){ // short s=60000; // cout<<s; cin>>n>>m; for(int i=0;i<m;i++){ int x,y; scanf("%d%d",&x,&y); if(i==0)f=x; if(i==1)t=x; v[x].pb(y); } dijkstra(); cout<<-1; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:94:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
#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...