This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#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];
struct kurac{
int xx;
int yy;
};
bool operator < (const kurac &prvi, const kurac &drugi){
return prvi.yy < drugi.yy;
}
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;
}
ff(i,1,n){
ff(j,1,n){
if(i == j)continue;
int dist = abs(niz[i].xx - niz[j].xx);
if(dist % niz[i].yy == 0)graf[i].pb({j, dist / niz[i].yy});
}
}
priority_queue<kurac> pq;
pq.push({1,0});
ff(i,1,n)dist[i] = 1e9;
dist[1] = 0;
while(!pq.empty()){
kurac sta = pq.top();
pq.pop();
if(sta.yy != dist[sta.xx])continue;
for(auto c:graf[sta.xx]){
if(dist[c.xx] > c.yy + sta.yy){
dist[c.xx] = c.yy + sta.yy;
pq.push({c.xx, dist[c.xx]});
}
}
}
if(dist[2] == 1e9)cout << -1 << "\n";
else cout << dist[2] << "\n";
return 0;
}
Compilation message (stderr)
skyscraper.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |