제출 #680174

#제출 시각아이디문제언어결과실행 시간메모리
680174minhcoolJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1085 ms202224 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; //gp_hash_table<int, int> table; using namespace std; //#define int long long #define fi first #define se second #define pb push_back #define mp make_pair #define foru(i, l, r) for(int i = l; i <= r; i++) #define ford(i, r, l) for(int i = r; i >= l; i--) #define eb emplace_back typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef pair<ii, ii> iiii; const int N = 3e4 + 5, MAXN = 1e7 + 5; const long long oo = 1e9 + 7, mod = 1e9 + 7; int n, m, b[N], p[N]; const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); struct chash { int operator()(int x) const { return x ^ RANDOM; } }; gp_hash_table<int, int, chash> mn_dist[N]; vector<int> vc[N]; vector<int> at[N]; set<ii> se; bool ck[N]; //unordered_map<int, vector<int>> avail[N]; void dijik(){ //priority_queue<iii, vector<iii>, greater<iii>> pq; deque<iii> pq; mn_dist[b[0]][p[0]] = 0; pq.push_front({0, {b[0], p[0]}}); while(!pq.empty()){ int u = pq.front().se.fi, d = pq.front().se.se; int dist = pq.front().fi; pq.pop_front(); if(dist != mn_dist[u][d]) continue; //cout << u << " " << d << " " << mn_dist[u][d] << "\n"; if(!ck[u]){ ck[u] = 1; for(auto it : at[u]){ if(mn_dist[u][it] > dist){ mn_dist[u][it] = dist; pq.push_front({mn_dist[u][it], {u, it}}); } } } if(d <= u && mn_dist[u - d][d] > mn_dist[u][d] + 1){ mn_dist[u - d][d] = mn_dist[u][d] + 1; pq.push_back({mn_dist[u - d][d], {u - d, d}}); } if((d + u) < n && mn_dist[u + d][d] > mn_dist[u][d] + 1){ mn_dist[u + d][d] = mn_dist[u][d] + 1; pq.push_back({mn_dist[u + d][d], {u + d, d}}); } } } void process(){ cin >> n >> m; int cnt = 0; for(int i = 0; i < m; i++){ cin >> b[i] >> p[i]; at[b[i]].pb(p[i]); if(se.find({b[i] % p[i], p[i]}) == se.end()){ se.insert({b[i] % p[i], p[i]}); for(int j = b[i] % p[i]; j < n; j += p[i]){ cnt++; vc[j].pb(p[i]); } } } for(int i = 0; i < n; i++){ for(auto it : vc[i]) mn_dist[i][it] = oo; } dijik(); int ans = mn_dist[b[1]][p[1]]; cout << (ans == oo ? -1 : ans); } signed main(){ ios_base::sync_with_stdio(0); process(); }
#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...