Submission #245566

#TimeUsernameProblemLanguageResultExecution timeMemory
245566mat_vJakarta Skyscrapers (APIO15_skyscraper)C++14
100 / 100
172 ms65768 KiB
#pragma GCC optimization ("O3") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n,m; pii niz[30005]; vector<pii> graf[30005]; int dist[30005]; set<int> pos[30005]; priority_queue<pii>pq; int main() { //ios_base::sync_with_stdio(false); cin.tie(0); cin >> m >> n; ff(i,1,n){ cin >> niz[i].xx >> niz[i].yy; pos[niz[i].xx].insert(niz[i].yy); } ff(i,0,m - 1){ for(auto c:pos[i]){ for(int j = i + c; j < m; j += c){ graf[i].pb({j, (j - i) / c}); if(pos[j].count(c))break; } for(int j = i - c; j >= 0; j -= c){ graf[i].pb({j, (i - j) / c}); if(pos[j].count(c))break; } } } ff(i,0,m - 1)dist[i] = 1e9; dist[niz[1].xx] = 0; pq.push({0,niz[1].xx}); while(!pq.empty()){ pii sta = pq.top(); pq.pop(); sta.xx = -sta.xx; if(dist[sta.yy] != sta.xx)continue; for(auto c:graf[sta.yy]){ if(dist[c.xx] > sta.xx + c.yy){ dist[c.xx] = sta.xx + c.yy; pq.push({-dist[c.xx], c.xx}); } } } if(dist[niz[2].xx] == 1e9)cout << -1 << "\n"; else cout << dist[niz[2].xx] << "\n"; return 0; }

Compilation message (stderr)

skyscraper.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
#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...