Submission #250012

#TimeUsernameProblemLanguageResultExecution timeMemory
250012EvirirJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1093 ms75376 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define setp(x) cout<<fixed<<setprecision(x) #define forn(i,a,b) for(int i=(a);i<(b);i++) #define fore(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define F first #define S second #define pqueue priority_queue #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef pair<ll,ii> iii; typedef vector<ll> vi; typedef vector<ii> vii; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; void amin(ll &a, ll b){ a=min(a,b); } void amax(ll &a, ll b){ a=max(a,b); } void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";} void SD(int t=0){ cout<<"PASSED "<<t<<endl; } const ll INF = ll(1e18); const int MOD = 998244353; const bool DEBUG = 0; const int MAXN = 30005; const int MAXP = 30005; const int MAXM = 30005; const int LIM = 300; int n,m; int a[MAXM],p[MAXM]; vi v[MAXN]; ll dist[MAXN][LIM]; priority_queue<iii,vector<iii>,greater<iii>> q; void add(ll x, ll y, ll w, ll d) { if(x<0 || x>=n) return; if(y>=LIM) { for(int i=x%y;i<n;i+=y){ add(i, 0, abs(x-i)/y, d); } } else { if(dist[x][y]>d+w){ dist[x][y]=d+w; q.push({dist[x][y],{x,y}}); } } } void dijkstra(ii src) { dist[src.F][src.S]=0; q.push({0,src}); while(!q.empty()) { ii u=q.top().S; q.pop(); if(u.S) { add(u.F-u.S, u.S, 1, dist[u.F][u.S]); add(u.F+u.S, u.S, 1, dist[u.F][u.S]); add(u.F, 0, 0, dist[u.F][u.S]); } else { for(int P: v[u.F]) { add(u.F, P, 0, dist[u.F][u.S]); } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; forn(i,0,m){ cin>>a[i]>>p[i]; v[a[i]].pb(p[i]); } forn(i,0,n) forn(j,0,LIM) dist[i][j]=INF; dijkstra({a[0],0}); if(dist[a[1]][0]<INF) cout<<dist[a[1]][0]<<'\n'; else cout<<-1<<'\n'; return 0; }
#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...