이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define ll int
#define ss second
#define ff first
#define INF 2000000000000000
#define pb push_back
#define edge pair<ll, pair<ll,ll> > // une, number ,power
#define cost first
#define num second.first
#define pwr second.second
ll n,m,l,r,i,j,ii,jj,k,x,y,D[30005][333],s,e;
vector< edge > v[30005][333]; // number , power (powergu oroi bol power = 179)
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>m;
for(i=1;i<=m;i++){
cin>>l>>r;
if(i==1) s=l;
if(i==2) e=l;
if(r>300)
for(j=1 ; l+r*j<n || l-r*j>=0 ; j++){
edge a;
a.num=l+r*j;
a.pwr=305;
a.cost=j;
if(a.num<n) v[l][305].pb(a);
a.num=l-r*j;
if(a.num>=0) v[l][305].pb(a);
}
else{
v[l][305].pb({0,{l,r}});
}
}
priority_queue<edge , vector< edge >, greater< edge > > q;
memset(D,-1,sizeof(D));
q.push({0,{s,200}});
while(!q.empty()){
ll une, nmbr, power;
une=q.top().cost;
nmbr=q.top().num;
power=q.top().pwr;
if(nmbr==e){
cout<<une;
return 0;
}
q.pop();
if(D[nmbr][power]!=-1);
else{
D[nmbr][power]=une;
for(edge no : v[nmbr][power]) if(D[no.num][no.pwr]==-1) q.push({une+no.cost,{no.num,no.pwr}});
if(power!=305){
if(D[nmbr][305]==-1) q.push({une,{nmbr,305}});
if(nmbr+power<n && D[nmbr+power][power]==-1) q.push({une+1,{nmbr+power,power}});
if(nmbr-power>=0 && D[nmbr-power][power]==-1) q.push({une+1,{nmbr-power,power}});
}
}
}
cout<<D[e][305];
}
# | 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... |