QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#589613 | #5073. Elden Ring | nekotorowo | WA | 189ms | 3640kb | C++20 | 3.1kb | 2024-09-25 18:58:29 | 2024-09-25 18:58:29 |
Judging History
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;
pair<vector<bool>, ll> all_reachable(const vector<vector<int>>& g, const vector<ll>& s, ll d) {
ll curs = s[0] - d;
int n = g.size();
vector<bool> used(n, false), reachable(n, false);
set<pair<ll, int>> h;
used[0] = true;
reachable[0] = true;
h.insert({0, 0});
while (!h.empty()) {
auto [sv, v] = *begin(h);
h.erase(begin(h));
if (curs <= sv && v != 0) {
break;
}
reachable[v] = true;
for (int u : g[v]) {
if (!used[u]) {
h.insert({s[u], u});
used[u] = true;
}
}
curs += d;
}
return {reachable, 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];
if (i > 0) {
s[i] += b;
}
}
if (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 (s[u] < s[0] + d * (a - b) && dist[u] > dist[v] + 1) {
dist[u] = dist[v] + 1;
h.insert({dist[u], u});
}
}
}
if (dist[n - 1] == INF64) {
cout << -1 << '\n';
} else {
cout << dist[n - 1] << '\n';
}
return ;
}
auto [reachable, maxs] = all_reachable(g, s, a - b);
if (reachable[n - 1] == false) {
cout << -1 << '\n';
return ;
}
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]) {
ll k = (s[u] - s[0] + 1) / (a - b);
if ((s[u] - s[0] + 1) % (a - b)) {
k++;
}
if (s[u] < maxs && dist[u] > max(dist[v] + 1, k + 1)) {
dist[u] = max(dist[v] + 1, k + 1);
h.insert({dist[u], u});
}
}
}
cout << dist[n - 1] << '\n';
return ;
}
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: 1ms
memory: 3572kb
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: 189ms
memory: 3640kb
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'