이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//Jakarta Skyscraper
const lg N = 300005;
lg dist[N], in_queue[N];
vector<set<pair<lg, lg>>> adj(N);
vector<lg> b(N), p(N);
void dijkstra(lg src)
{
priority_queue<array<lg, 2>> pq;
pq.push({0, src});
in_queue[src] = 1;
memset(dist, 0x3f, sizeof(dist));
dist[src] = 0;
while(pq.size())
{
lg x = pq.top()[1];
in_queue[x] = 0;
pq.pop();
for(auto [it, c] : adj[x])
{
if(dist[it] > dist[x]+c)
{
dist[it] = dist[x]+c;
if(!in_queue[it]) pq.push({-dist[it], it});
in_queue[it] = true;
}
}
}
return;
}
int main()
{
fastio;
lg n, m;
cin >> n >> m;
for(int i = 0; i < m; i++)
{
cin >> b[i] >> p[i];
}
map<array<lg, 2>, lg> mp;
for(int i = 0; i < m; i++)
{
lg x = b[i]%p[i];
if(mp[{x, b[i]}]) continue;
// cout << i << ' ';
mp[{x, b[i]}] = true;
for(int j = x; j < n; j += p[i])
{
if(j == b[i]) continue;
adj[b[i]].insert({j, abs(b[i]-j)/p[i]});
}
}
dijkstra(b[0]);
if(dist[b[1]] == dist[N-1])
{
cout << "-1\n";
return 0;
}
cout << dist[b[1]] << '\n';
return 0;
}
# | 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... |