#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e4+2;
const int INF=2e9;
int n,m;
struct doge
{
int p,pos;
bool operator<(const doge& other)
{
if(pos!=other.pos)return pos<other.pos;
return p<=other.p;
}
}d[MAXN];
struct state
{
int pos,p,d;
bool operator<(state const& other)const
{
if(d!=other.d)return d>other.d;
return make_pair(p,pos)<make_pair(other.p,other.pos);
}
};
set<pair<int,int> >doges;
vector<int>doges1[MAXN];
vector<int>states;
unordered_map<int,int>dist;
int main()
{
srand(65435);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(int i=0;i<m;++i)
{
cin>>d[i].pos>>d[i].p;
doges.insert({d[i].p,d[i].pos%d[i].p});
doges1[d[i].pos].push_back(d[i].p);
}
for(auto t:doges)
{
for(int i=t.second;i<n;i+=t.first)
{
states.push_back(i*MAXN+t.first);
}
}
for(auto s:states)
{
dist[s]=INF;
used[s]=0;
}
priority_queue<state>pq;
pq.push({d[0].pos,d[0].p,0});
dist[d[0].pos*MAXN+d[0].p]=0;
while(!pq.empty())
{
state u=pq.top();pq.pop();
if(dist[u.pos*MAXN+u.p]<u.d)continue;
if(u.pos==d[1].pos&&u.p==d[1].p)break;
for(auto d1:doges1[u.pos])
{
if(d1==u.p)continue;
if(dist[u.pos*MAXN+d1]>u.d)
{
dist[u.pos*MAXN+d1]=u.d;
pq.push({u.pos,d1,u.d});
}
}
state v=u;
if(v.pos-v.p>=0)
{
v.pos-=v.p;
if(dist[v.pos*MAXN+v.p]>u.d+1)
{
v.d=u.d+1;
dist[v.pos*MAXN+v.p]=v.d;
pq.push(v);
}
}
v=u;
if(v.pos+v.p<n)
{
v.pos+=v.p;
if(dist[v.pos*MAXN+v.p]>u.d+1)
{
v.d=u.d+1;
dist[v.pos*MAXN+v.p]=v.d;
pq.push(v);
}
}
}
if(dist[d[1].pos*MAXN+d[1].p]==INF)
{
cout<<-1<<"\n";
}
else cout<<dist[d[1].pos*MAXN+d[1].p]<<"\n";
return 0;
}
Compilation message
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:51:3: error: 'used' was not declared in this scope
51 | used[s]=0;
| ^~~~