제출 #388808

#제출 시각아이디문제언어결과실행 시간메모리
388808talant117408Jakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
394 ms262148 KiB
/* Code written by Talant I.D. */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define precision(n) fixed << setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define eps (double)1e-9 #define PI 2*acos(0.0) #define endl "\n" #define sz(v) int((v).size()) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define OK cout << "OK" << endl; const int mod = 998244353; ll mode(ll a) { a %= mod; if (a < 0) a += mod; return a; } ll subt(ll a, ll b) { return mode(mode(a)-mode(b)); } ll add(ll a, ll b) { return mode(mode(a)+mode(b)); } ll mult(ll a, ll b) { return mode(mode(a)*mode(b)); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b&1) res = mult(res, a); a = mult(a, a); b >>= 1; } return res; } const int N = 3e4+7; int dist[N], who[N]; vector <pii> graph[N]; int main() { do_not_disturb int h, n; cin >> h >> n; vector <pii> doges(n); for (auto &to : doges) cin >> to.first >> to.second; for (int i = 0; i < n; i++) { who[doges[i].first]++; } for (int i = 0; i < n; i++) { int cnt = 0; int jump = doges[i].second; for (int pos = doges[i].first; pos < h; pos += jump) { if (who[pos] && pos != doges[i].first) { graph[doges[i].first].pb(mp(pos, cnt)); } cnt++; } cnt = 0; for (int pos = doges[i].first; pos >= 0; pos -= jump) { if (who[pos] && pos != doges[i].first) { graph[doges[i].first].pb(mp(pos, cnt)); } cnt++; } } for (int i = 0; i < h; i++) { dist[i] = 1e9; } dist[doges[0].first] = 0; priority_queue <pii> K; K.push(mp(0, doges[0].first)); while(!K.empty()) { auto v = K.top().second; K.pop(); for (auto to : graph[v]) { if (dist[to.first] > dist[v]+to.second) { dist[to.first] = dist[v]+to.second; K.push(mp(-dist[to.first], to.first)); } } } if (dist[doges[1].first] >= 1e9) cout << -1; else cout << dist[doges[1].first]; 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...