QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604346 | #5073. Elden Ring | AngelOlan | WA | 183ms | 3792kb | C++20 | 2.2kb | 2024-10-02 10:04:26 | 2024-10-02 10:04:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// Pura Gente del Coach Moy
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define ROF(i, a, b) for (int i = (int)a - 1; i >= (int)b; --i)
#define ENDL '\n'
constexpr int INF = 1e9 + 5;
void solve_less_eq(int A, int B, vector<vi>& g, vi& a) {
int N = SZ(g);
vi d(N, -1);
d[0] = 0;
queue<int> q;
q.push(0);
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto &v : g[u]) if (d[v] == -1 && (ll)A * d[u] + a[0] > (ll)B * d[u] + a[v]) {
d[v] = d[u] + 1;
q.push(v);
}
}
cout << d[N - 1] << ENDL;
}
int find_max_time(int D, vector<vi>& g, vi& a) {
int N = SZ(g), t = -1;
vi vis(N);
vis[0] = 1;
priority_queue<pi> pq;
pq.push({1, 0});
while (!pq.empty() && -pq.top().first <= t) {
int u = pq.top().second;
pq.pop();
for (auto &v : g[u]) if (!vis[v]) {
vis[v] = 1;
int dv = a[v] <= a[0] ? 0 : ((a[v] - a[0]) / D + 1);
pq.push({-dv, v});
}
++t;
}
return t;
}
void solve_greater(int D, vector<vi>& g, vi& a) {
int N = SZ(g);
vi d(N, INF);
d[0] = 0;
priority_queue<pi> pq;
pq.push({0, 0});
int mx_time = find_max_time(D, g, a);
while (!pq.empty()) {
auto [du, u] = pq.top();
du = -du;
pq.pop();
if (du > d[u]) continue;
for (auto &v : g[u]) {
int dx = max(du, (a[v] - a[0]) / D + 1);
if (dx <= mx_time && dx + 1 < d[v]) {
d[v] = dx + 1;
pq.push({-d[v], v});
}
}
}
if (d[N - 1] == INF) d[N - 1] = -1;
cout << d[N - 1] << ENDL;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int N, M, A, B;
cin >> N >> M >> A >> B;
vector<vi> g(N);
while (M--) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].pb(v), g[v].pb(u);
}
vi a(N);
FOR (i, 0, N) {
cin >> a[i];
if (i) a[i] += B;
}
if (A <= B) solve_less_eq(A, B, g, a);
else solve_greater(A - B, g, a);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
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: 183ms
memory: 3564kb
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:
wrong answer 151st numbers differ - expected: '2', found: '3'