蒟蒻的基霸代码求调
其中f数组定义int和unsigned long long对于样例二的输出还不一样(神奇
#include<bits/stdc++.h>
using namespace std;
#define LL unsigned long long
const int N=1e5+10;
LL h,ans;
LL f[N];
int x,y,z;
int head[N],ne[N],enter[N],dat[N],idx;
bool vis[N];
void add(int u,int v,int w)
{
dat[idx]=w;
enter[idx]=v;
ne[idx]=head[u];
head[u]=idx++;
}
void dij()
{
typedef pair<LL,int> PII;
priority_queue<PII,vector<PII>,greater<PII> > que;
que.push({1,1}); f[1]=1;
while(!que.empty())
{
PII x=que.top();LL d=x.first;int pos=x.second;que.pop();
if(vis[pos]) continue;
vis[pos]=1;
for(int i=head[pos];i!=-1;i=ne[i])
{
int y=enter[i];
if(f[y]>dat[i]+d)
{
f[y]=dat[i]+d;
que.push({f[y],y});
}
}
}
}
int main()
{
memset(f,0x3f,sizeof f);
memset(head,-1,sizeof head);
cin>>h>>x>>y>>z;
for(int i=0;i<z;i++)//走x y
{
add(i,(i+x)%z,x);//f(i+x)=f(i)+x
add(i,(i+y)%z,y);//f(i+y)=f(i)+y
}
dij();
for(int i=0;i<z;i++)
if(f[i]<=h)
ans+=(h-f[i])/z+1;
cout<<ans;
}