# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1184589 | inesfi | Jakarta Skyscrapers (APIO15_skyscraper) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
const int TAILLEMAXI=30*1000+2,PMAXI=172;
int dejavu[TAILLEMAXI][TAILLEMAXI]; ///endroit,P
vector<int> depart[TAILLEMAXI];
int nbvilles,nbjumpers;
priority_queue<tuple<int,int,int>> encours; ///////// -nbcoups, pos, P
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>nbvilles>>nbjumpers;
int posfinal;
for (int i=0;i<nbjumpers;i++){
int a,b;
cin>>a>>b;
depart[a].push_back(b);
if (i==0){
encours.push_back(make_tuple(0,a,0));
}
else if (i==1){
posfinal=a;
}
}
while (encours.size()!=0){
int nbcoups=get<0>(encours.top()),pos=get<1>(encours.top()),P=get<2>(encours.top());
encours.pop();
if (pos>=0 and pos<nbvilles and dejavu[pos][P]==0){
dejavu[pos][P]=1;
if (pos==posfinal){
cout<<-nbcoups<<endl;
return 0;
}
if (P!=0){
encours.push(make_tuple(nbcoups,pos,0));
encours.push(make_tuple(nbcoups-1,pos-P,P));
encours.push(make_tuple(nbcoups-1,pos+P,P));
}
else {
for (int i:depart[pos]){
if (i<PMAXI){
encours.push(make_tuple(nbcoups,pos,P));
}
else {
int a=1;
while (pos-a*P>=0){
encours.push(make_tuple(nbcoups-a,pos-a*P,0));
a++;
}
a=1;
while (pos+a*P<nbvilles){
encours.push(make_tuple(nbcoups-a,pos+a*P,0));
a++;
}
}
}
}
}
}
cout<<-1<<endl;
return 0;
}