Submission #232489

#TimeUsernameProblemLanguageResultExecution timeMemory
232489balbitJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
5 ms436 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__) template<typename T> void _do(T && x){cerr<<x<<endl;} template<typename T, typename ...S> void _do(T && x, S&&...y){cerr<<x<<", "; _do(y...);} #define IOS() #else #define bug(...) #define IOS() ios::sync_with_stdio(0), cin.tie(0) #define endl '\n' #endif // BALBIT #define pii pair<int, int> #define f first #define s second #define ALL(x) x.begin(), x.end() #define SZ(x) (int)(x.size()) #define pb push_back const int maxn = 2005; vector<pii> g[maxn]; int d[maxn]; set<pii> bp; signed main(){ IOS(); int n,m; cin>>n>>m; int S = -1, T = -1; for (int i = 0; i<m; ++i) { int b,p; cin>>b>>p; if (i == 0) S = b; if (i == 1) T = b; if (bp.count({b,p})) continue; bp.insert({b,p}); for (int j = 0; j<n; ++j) { if ((j-b) % p == 0 && j!=b) { g[b].pb({j,abs(j-b)/p}); } } } memset(d, 0x3f, sizeof d); d[S] = 0; priority_queue<pii, vector<pii>, greater<pii> > pq; pq.push({0,S}); while (!pq.empty()) { int v = pq.top().s; int w = pq.top().f; pq.pop(); bug(v, d[v]); if (d[v] != w) { continue; } for (pii u : g[v]) { if (d[u.f] > d[v] + u.s) { d[u.f] = d[v] + u.s; pq.push({d[u.f], u.f}); } } } cout<<d[T]<<endl; }
#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...