Submission #338193

#TimeUsernameProblemLanguageResultExecution timeMemory
338193bigDuckJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
570 ms262148 KiB
#include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount int t, n, m, k, b[30010], p[30010]; int crd[30010]; int d[30010]; bool v[30010]; bool dog[30010]; vector<pii> g[30010]; set<int> dgs[30010]; void dijkstra(){ multiset<pii> ms; ms.insert({d[crd[1] ], crd[1]}); while(!ms.empty()){ auto f=*ms.begin(); ms.erase(ms.begin()); int nod=f.sc; v[nod]=true; //cout<<nod<<"y\n"; if(nod==crd[2]); for(auto pr:g[nod]){ int u=pr.ft, c=pr.sc; if(v[u]){continue;} //cout<<u<<" "<<c<<"x\n"; auto it=ms.find({d[u], u}); if(it!=ms.end()){ ms.erase(it); d[u]=min(d[u], d[nod]+c); ms.insert({d[u], u}); } else{ d[u]=d[nod]+c; ms.insert({d[u], u} ); } } } return; } int32_t main(){ INIT cin>>n>>m; for(int i=1; i<=n; i++){d[i]=-1;} for(int i=1; i<=m; i++){ cin>>b[i]>>p[i]; b[i]++; dog[b[i] ]=true; dgs[b[i] ].insert({p[i]}); crd[i ]=b[i]; } for(int nod=1; nod<=n; nod++){ for(auto it=dgs[nod].begin(); it!=dgs[nod].end(); it++){ int p=*it; for(int j=nod-p; j>=1; j-=p){ if((dog[j]) ){ // g[j].pb({b[i], abs(b[i]-j)/p[i] }); g[nod ].pb({j, abs(nod-j)/p });} } for(int j=nod+p; j<=n; j+=p){ if( (dog[j]) ){ //g[j].pb({b[i], abs(b[i]-j)/p[i] }); g[nod ].pb({j, abs(nod-j)/p });} } } } d[crd[1] ]=0; dijkstra(); cout<<d[crd[2] ]; 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...