QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588139#5073. Elden RingnekotorowoWA 250ms3616kbC++202.6kb2024-09-25 02:57:252024-09-25 02:57:25

Judging History

你现在查看的是最新测评结果

  • [2024-09-25 02:57:25]
  • 评测
  • 测评结果:WA
  • 用时:250ms
  • 内存:3616kb
  • [2024-09-25 02:57:25]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second

using ll = long long int;
using ld = long double;

const int INF = 1000000007;
const ll INF64 = 1000000000000000003LL;
const int CUTE_LOGN = 17;

ll calc_end_s(const vector<vector<int>>& g, const vector<ll>& s, ll d) {
    ll curs = s[0];
    int n = g.size();
    vector<bool> used(n, false);
    set<pair<ll, int>> h;

    h.insert({0, 0});

    while (!h.empty()) {
        auto [sv, v] = *begin(h);
        if (curs < sv) {
            break;
        }
        h.erase(begin(h));
        used[v] = true;
        curs += d;
        for (int u : g[v]) {
            if (!used[u]) {
                h.insert({s[u], u});
            }
        }
    }

    return curs;
}

void solve() {
    int n, m;
    vector<ll> dist, s;
    vector<vector<int>> g;
    set<pair<ll, int>> h;
    ll a, b;

    cin >> n >> m >> a >> b;

    g.resize(n);
    for (int i = 0; i < m; i++) {
        int v, u;

        cin >> v >> u;
        v--, u--;

        g[v].push_back(u);
        g[u].push_back(v);
    }
    s.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    ll maxs = max(s[0], calc_end_s(g, s, a - b));

    dist.resize(n, INF64);
    dist[0] = 0;
    h.insert({0, 0});
    while (!h.empty()) {
        auto [d, v] = *begin(h);
        h.erase(begin(h));

        if (dist[v] != d) { continue; }

        for (int u : g[v]) {
            if (a <= b) {
                if (s[u] < s[0] + d * (a - b) && dist[u] > dist[v] + 1) {
                    dist[u] = dist[v] + 1;
                    h.insert({dist[u], u});
                    //cout << "OWO " << dist[u] << '\n';
                }
            } else {
                if (s[u] < s[0] + d * (a - b) && dist[u] > dist[v] + 1) {
                    dist[u] = dist[v] + 1;
                    h.insert({dist[u], u});
                } else if (s[u] < maxs && dist[u] > 1 + (s[u] - s[0] + a - b + 1) / (a - b)) {
                    dist[u] = 1 + (s[u] - s[0] + a - b + 1) / (a - b);
                    //cout << "UWU " << dist[u] << '\n';
                    h.insert({dist[u], u});
                }
            }
        }
    }

    if (dist[n - 1] == INF64) {
        cout << -1 << '\n';
    } else {
        cout << dist[n - 1] << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;

    for (int i = 0; i < t; i++) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3492kb

input:

2
5 4 5 8
1 2
1 3
1 4
4 5
15 1 1 1 1
5 4 10 5
1 2
1 3
1 4
4 5
10 4 4 4 19

output:

2
4

result:

ok 2 number(s): "2 4"

Test #2:

score: -100
Wrong Answer
time: 250ms
memory: 3616kb

input:

100000
6 10 107812 105568
6 5
3 6
4 6
4 2
5 1
5 6
4 5
1 3
1 2
2 5
124065 140875 29890 80077 116532 35394
9 10 82107 88302
1 2
2 3
5 3
5 1
1 4
9 6
3 5
8 2
5 6
7 5
22670 3735 33660 92823 139960 89319 83335 158330 117349
6 10 181257 173221
5 3
3 4
3 1
5 1
2 1
3 6
3 1
6 2
3 6
4 3
76902 46253 123092 2661...

output:

-37
-1
-1
-20
-1
1
1
3
-4
-1
1
1
2
4
-1
-1
-1
-7
-1
-1
-1
1
-1
2
-1
3
-1
-1
1
-1
-1
-1
-1
-1
6
-1
-1
-1
-1
-7
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
2
-1
2
-9
-1
-5
1
-1
-1
1
2
-1
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
3
1
2
-1
-1
-1
1
1
-1
-1
-15
1
-1
1
-1
-1
-1
-1
-1
-1
-16
-10
-1
-1
-1
1
-1
-1
-1
-1
-1...

result:

wrong answer 1st numbers differ - expected: '-1', found: '-37'