QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#311562 | #5073. Elden Ring | Dinshey | WA | 161ms | 14080kb | C++14 | 2.5kb | 2024-01-22 15:15:33 | 2024-01-22 15:15:33 |
Judging History
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];
signed main() {
scanf("%lld", &T);
while (T--) {
scanf("%lld%lld%lld%lld", &n, &m, &A, &B);
for (int i = 1, u, v; i <= m; ++i) {
scanf("%lld%lld", &u, &v);
e[u].push_back(v);
e[v].push_back(u);
}
for (int i = 1; i <= n; ++i) scanf("%lld", l + i);
--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});
}
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) {
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]);
}
puts("-1");
}
end:
for (int i = 1; i <= n; ++i) e[i].clear();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 12304kb
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: 153ms
memory: 14080kb
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: 161ms
memory: 14048kb
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:
-1 -1 7 -1 -1 -1 -1 -1 -1 4 -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 4 -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 4 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 -1 1 3 -1 -1 1 1 -1 -1 -1 5 1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer 47983rd numbers differ - expected: '2', found: '4'