QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#663688 | #5540. City Hall | ucup-team3519# | WA | 76ms | 14164kb | C++17 | 2.7kb | 2024-10-21 16:45:23 | 2024-10-21 16:45:30 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = int64_t;
template <typename T>
using minpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;
constexpr i64 INF = 1e18;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, s, t;
std::cin >> n >> m >> s >> t;
--s, --t;
std::vector<int> h(n);
for (int &i : h) {
std::cin >> i;
}
std::vector<std::vector<int>> adj(n);
for (int i = 0; i < m; ++i) {
int u, v;
std::cin >> u >> v;
--u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
auto get_dist = [&](int src) -> std::vector<i64> {
std::vector<i64> dist(n, INF);
minpq<std::pair<i64, int>> q;
dist[src] = 0;
q.emplace(dist[src], src);
std::vector<uint8_t> vist(n);
while (!q.empty()) {
auto [_, node] = q.top();
q.pop();
if (vist[node]) continue;
vist[node] = true;
for (int to : adj[node]) {
i64 w = i64(h[node] - h[to]) * (h[node] - h[to]);
if (dist[to] > dist[node] + w) {
dist[to] = dist[node] + w;
q.emplace(dist[to], to);
}
}
}
return dist;
};
std::vector<i64> f = get_dist(s), g = get_dist(t);
i64 ans = INF;
for (int to : adj[s]) {
ans = std::min(ans, g[to]);
}
for (int to : adj[t]) {
ans = std::min(ans, f[to]);
}
auto check = [&](int x) -> void {
auto a = adj[x];
std::sort(a.begin(), a.end(), [&](int x, int y) {
return h[x] < h[y];
});
auto val = [&](int x, int y) -> i64 {
return 2 * (f[x] + g[y]) + (h[x] - h[y]) * (h[x] - h[y]);
};
auto solve = [&](auto &self, int L, int R, int l, int r) -> void {
if (l > r) return;
int mid = (l + r) / 2;
int x = std::min(R, mid - 1);
i64 res = val(a[x], a[mid]);
for (int i = x - 1; i >= L; --i) {
if (val(a[i], a[mid]) < res) {
x = i;
res = val(a[x], a[mid]);
}
}
ans = std::min(ans, res);
self(self, L, x, l, mid - 1);
self(self, x, R, mid + 1, r);
};
solve(solve, 0, a.size() - 1, 1, a.size() - 1);
std::reverse(a.begin(), a.end());
solve(solve, 0, a.size() - 1, 1, a.size() - 1);
};
for (int i = 0; i < n; ++i) {
check(i);
}
std::cout << ans / 2;
if (ans % 2 == 1) {
std::cout << ".5";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
5 6 1 3 5 100 8 2 10 1 2 2 3 2 5 1 4 4 5 3 5
output:
4.5
result:
ok found '4.5000000', expected '4.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5 5 1 5 1 2 10 10 4 1 2 2 3 2 4 3 5 4 5
output:
3
result:
ok found '3.0000000', expected '3.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
5 4 1 4 8 8 8 8 100 1 2 2 3 3 4 4 5
output:
0
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 1 1 2 0 100000 1 2
output:
0
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #5:
score: -100
Wrong Answer
time: 76ms
memory: 14164kb
input:
632 199396 167 549 22513 93521 41403 35441 97617 53210 62622 4751 81863 14470 2994 93092 40432 30872 34423 36577 92540 92961 4110 14691 83321 10680 89112 80890 31108 24492 8973 42636 33792 27400 82361 85003 68940 31221 48625 276 52755 6649 34381 54399 6063 22628 17715 54052 58175 86609 82622 29917 9...
output:
-1044869453
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '-1044869453.0000000', error = '1044869453.0000000'