rt,第一个样例都没过怎么A了。
#include<bits/stdc++.h>
#define int long long
using namespace std;
int h,x,y,z;
struct node{
int v,w;
bool operator < (const node & hh) const {
return w > hh.w;
}
};
vector<node>g[2000005];
int dis[2000005],vis[20000005];
inline void dijkstra(int st) {
for(int i = 0;i <= x;++i) dis[i] = 1e18;
priority_queue<node>q;
dis[st] = 1;
q.push(node{st,1});
while(!q.empty()) {
node tp = q.top();
q.pop();
if(vis[tp.v]) continue;
vis[tp.v] = 1;
for(auto x : g[tp.v]) {
if(dis[x.v] > dis[tp.v] + x.w){
dis[x.v] = dis[tp.v] + x.w;
q.push(node{x.v,dis[x.v]});
}
}
}
int ans = 0;
for(int i = 0;i < x;++i) if(h > dis[i])ans += (h - dis[i]) / x + 1;
cout << ans << '\n';
return ;
}
signed main(){
cin >> h >> x >> y >> z;
if(x == 1 || y == 1 || z == 1) return cout << h << '\n' ,0;
for(int i = 0;i < x;++i) {
g[i].push_back(node{(i + y) % x,y});
g[i].push_back(node{(i + z) % x,z});
}
dijkstra(0);
return 0;
}