29 lines
952 B
C++
29 lines
952 B
C++
// P3403 跳楼机。楼层减一,按最小步长的余数建图。
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
using ll = long long;
|
|
int main() {
|
|
ios::sync_with_stdio(false); cin.tie(nullptr);
|
|
ll h; array<int,3> step;
|
|
if (!(cin >> h >> step[0] >> step[1] >> step[2])) return 0;
|
|
sort(step.begin(), step.end()); int m = step[0];
|
|
const ll INF = 1LL << 60;
|
|
vector<ll> d(m, INF);
|
|
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
|
|
d[0] = 0; pq.push({0,0});
|
|
while (!pq.empty()) {
|
|
auto [du,u] = pq.top(); pq.pop();
|
|
if (du != d[u]) continue;
|
|
for (int i = 1; i <= 2; ++i) {
|
|
int w = step[i], v = (u+w)%m;
|
|
if (du + w < d[v]) { d[v] = du+w; pq.push({d[v],v}); }
|
|
}
|
|
}
|
|
ll L = h-1, ans = 0;
|
|
for (int r = 0; r < m; ++r) {
|
|
if (d[r] == INF || d[r] > L) continue;
|
|
ans += (L-d[r])/m + 1;
|
|
}
|
|
cout << ans << '\n';
|
|
}
|