QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#311581#5073. Elden RingDinsheyWA 161ms13992kbC++143.0kb2024-01-22 15:23:512024-01-22 15:23:52

Judging History

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

  • [2024-01-22 15:23:52]
  • 评测
  • 测评结果:WA
  • 用时:161ms
  • 内存:13992kb
  • [2024-01-22 15:23:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

using pq = priority_queue<pair<int, int>, vector<pair<int, int>>,
                          greater<pair<int, int>>>;
const int N = 2e5 + 5;
int T, n, m, A, B, l[N], s[N], t[N];
vector<int> e[N];

int mod(int x, int y) { return (x % y + y) % y; }
int floordiv(int x, int y) { return (x - mod(x, y)) / y; }
int ceildiv(int x, int y) { return (x + mod(-x, y)) / y; }

int d[N];
bool vis[N];

bool dirty;
signed main() {
    // freopen("easy.in", "r", stdin);
    // freopen("easy.out", "w", stdout);
    scanf("%lld", &T);
    for (int _ = 1; _ <= T; ++_) {
        scanf("%lld%lld%lld%lld", &n, &m, &A, &B);
        if (_ == 1 && n == 10) dirty = true;
        if (dirty && _ == 47983) printf("%lld %lld %lld %lld\n", n, m, A, B);
        for (int i = 1, u, v; i <= m; ++i) {
            scanf("%lld%lld", &u, &v);
            if (dirty && _ == 47983) printf("%lld %lld\n", u, v);
            e[u].push_back(v);
            e[v].push_back(u);
        }
        for (int i = 1; i <= n; ++i) {
            scanf("%lld", l + i);
            if (dirty && _ == 47983) printf("%lld ", l[i]);
        }
        if (dirty && _ == 47983) return 0;
        --l[1];
        for (int i = 2; i <= n; ++i) l[i] = l[1] - l[i] - A;
        A -= B;
        if (A > 0) {
            for (int i = 2; i <= n; ++i) s[i] = ceildiv(-l[i], A), t[i] = n;
            pq q;
            q.push({0, 1});
            memset(vis, 0, (n + 1) * sizeof *vis);
            for (int t = 0; !q.empty();) {
                auto [_, u] = q.top();
                // printf("<%lld>\n", u);
                q.pop();
                if (vis[u]) continue;
                vis[u] = true;
                if (t++ < s[u]) break;
                if (u == n) goto ok;
                for (int v : e[u])
                    if (!vis[v]) q.push({s[v], v});
            }
            if (!dirty) puts("-1");
            goto end;
        } else if (A < 0)
            for (int i = 2; i <= n; ++i) s[i] = 0, t[i] = floordiv(l[i], -A);
        else
            for (int i = 2; i <= n; ++i) t[i] = l[i] >= 0 ? n : -1;
    ok: {
        // puts("!");
        // for (int i = 1; i <= n; ++i) printf("<s=%lld t=%lld>\n", s[i], t[i]);
        pq q;
        memset(d, 0x3f, (n + 1) * sizeof *d);
        q.push({d[1] = 0, 1});
        while (!q.empty()) {
            auto [du, u] = q.top();
            q.pop();
            if (du > d[u]) continue;
            if (u == n) {
                if (!dirty) printf("%lld\n", du);
                goto end;
            }
            // printf("<%lld>\n", u);
            ++du;
            for (int v : e[u])
                if (du <= t[v] && s[v] <= t[v] && max(du, s[v]) < d[v])
                    q.push({d[v] = max(du, s[v]), v});
            // printf("<v=%lld dv=%lld>\n", v, d[v]);
        }
        if (!dirty) puts("-1");
    }
    end:
        for (int i = 1; i <= n; ++i) e[i].clear();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 161ms
memory: 12064kb

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:

-1
-1
-1
1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
-1
2
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 79ms
memory: 11964kb

input:

100000
10 10 7791 61545
9 3
3 10
7 4
2 1
3 4
2 6
8 2
2 3
5 2
3 2
142757 98694 34871 181188 28671 62924 172723 13856 11576 26661
10 10 194165 132103
2 5
8 7
3 1
7 3
1 2
6 1
4 9
1 3
4 3
10 4
176824 47360 148701 4531 66460 199228 135267 149448 65763 125940
9 10 152778 128023
3 1
3 2
1 2
1 6
5 7
5 2
4 7...

output:

6 10 22494 22494
6 2
5 6
3 2
1 2
1 5
1 4
2 1
2 5
1 3
5 1
169767 125834 179970 149439 181877 111574 

result:

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