Submission #738705

#TimeUsernameProblemLanguageResultExecution timeMemory
738705MauveJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
298 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ss second #define ff first #define INF 2000000000000000 #define pb push_back #define edge pair<ll, pair<ll,ll> > // une, number ,power #define cost first #define num second.first #define pwr second.second ll n,m,l,r,i,j,ii,jj,k,x,y,D[30005][180],s,e; vector< edge > v[30005][180]; // number , power (powergu oroi bol power = 179) int main(){ cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cin>>n>>m; for(i=1;i<=m;i++){ cin>>l>>r; if(i==1) s=l; if(i==2) e=l; if(r>175) for(j=1 ; l+r*j<n || l-r*j>=0 ; j++){ edge a; a.num=l+r*j; a.pwr=179; a.cost=j; if(a.num<n) v[l][179].pb(a); a.num=l-r*j; if(a.num>=0) v[l][179].pb(a); } else{ v[l][179].pb({0,{l,r}}); } } for(i=1;i<=175;i++) for(j=0;j<n;j++){ v[j][i].pb({0,{j,179}}); if(j+i<n) v[j][i].pb({1,{j+i,i}}); if(j-i>=0) v[j][i].pb({1,{j-i,i}}); } priority_queue<edge , vector< edge >, greater< edge > > q; memset(D,-1,sizeof(D)); q.push({0,{s,179}}); while(!q.empty()){ ll une, nmbr, power; une=q.top().cost; nmbr=q.top().num; power=q.top().pwr; q.pop(); if(D[nmbr][power]!=-1) continue; D[nmbr][power]=une; for(edge no : v[nmbr][power]) if(D[no.num][no.pwr]==-1) q.push({une+no.cost,{no.num,no.pwr}}); } cout<<D[e][179]; }
#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...