이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,m,s,e;
vector<pair<int,int> > adj[30001];
set<int> pos[30001];
int dist[30001];
bool vis[30001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for (int i=0;i<m;i++){
int b,p;
cin>>b>>p;
if (i==0) s=b;
if (i==1) e=b;
pos[p].insert(b);
}
for (int i=1;i<30001;i++){
memset(vis,false,sizeof(vis));
for (auto j:pos[i]){
vis[j]=true;
}
for (auto j:pos[i]){
int dis=1;
for (int k=j+i;k<n;k+=i){
adj[j].pb(mp(k,dis));
dis++;
if (vis[k]) break;
}
dis=1;
for (int k=j-i;k>=0;k-=i){
adj[j].pb(mp(k,dis));
dis++;
if (vis[k]) break;
}
}
}
memset(dist,-1,sizeof(dist));
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >pq;
pq.push(mp(0,s));
while (!pq.empty()){
pair<int,int> cur=pq.top();
pq.pop();
if (dist[cur.second]!=-1) continue;
dist[cur.second]=cur.first;
for (auto i:adj[cur.second]){
pq.push(mp(cur.first+i.second,i.first));
}
}
cout<<dist[e];
}
# | 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... |