Submission #391275

#TimeUsernameProblemLanguageResultExecution timeMemory
391275BlagojceJakarta Skyscrapers (APIO15_skyscraper)C++11
57 / 100
1086 ms9808 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int i_inf = 1e9; const ll inf = 1e18; const ll mod = 1e9+7; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t z; const int mxn = 4e4; int n, m; ll b[mxn], p[mxn]; ll dist[mxn]; vector<ll> g[mxn]; bool vis[mxn]; bool con[500][mxn]; void solve(){ cin >> n >> m; fr(i, 0, m){ cin >> b[i] >> p[i]; g[b[i]].pb(p[i]); if(p[i] < 500) con[p[i]][b[i]] = true; } fr(i, 0, n) dist[i] = inf; pq <pair<ll,int> > Q; Q.push({0, b[0]}); dist[b[0]] = 0; while(!Q.empty()){ int c = Q.top().nd; ll w = Q.top().st; Q.pop(); if(c == b[1]){ cout<<-w<<endl; return; } if(vis[c]) continue; vis[c] = true; for(auto u : g[c]){ for(int i = c + u; i < n; i += u){ if(dist[c] + (i-c)/u < dist[i]){ dist[i] = dist[c] + (i-c)/u; Q.push({-dist[i], i}); } if(u < 500 && con[u][i]) break; } for(int i = c - u; i >=0; i -= u){ if(dist[c] + (c-i)/u < dist[i]){ dist[i] = dist[c] + (c-i)/u; Q.push({-dist[i], i}); } if(u < 500 && con[u][i]) break; } } } cout<<-1<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#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...