90分,第八个点没过,求助
查看原帖
90分,第八个点没过,求助
1145337
Phantom_Landler楼主2024/10/5 15:43
#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long ull;
typedef pair<long long, int> PII;
const int N = 2000010;
ull h[N], e[N], ne[N], w[N], idx;
const unsigned long long INF = (1ull << 63)-1;

void add(int a, int b, int c) {
    e[++idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx;
}

ull dist[N];
bool st[N];

priority_queue<PII,vector<PII>,greater<PII> > heap;
void dijstkra() {
    dist[0] = 0;
    heap.push({0, 0});
    while (!heap.empty()) {
        auto t = heap.top();
        heap.pop();
        int dis = t.first, ver = t.second;
        if (st[ver]) continue;
        st[ver] = true;
        for (int i = h[ver]; i; i = ne[i]) {
            int j = e[i];
            if (dist[j] > dis + w[i]) {
                dist[j] = dis + w[i];
                heap.push({dist[j], j});
            }
        }
    }
}

int main() {
    unsigned long long hi;
    cin >> hi;
    int x, y, z;
    cin >> x >> y >> z;
    hi--;
    for (int i = 0; i < x; i++) {
        add(i,(i + y) % x,y);
        add(i, (i + z) % x, z);
        dist[i] = INF;
    }
    dijstkra();
    ull ans = 0;
    for (int i = 0; i < x; i++)
        if (hi >= dist[i]) ans += (hi - dist[i]) / x + 1;
    cout << ans;
    return 0;
}

2024/10/5 15:43
加载中...