QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#475881 | #5540. City Hall | Thirvin | WA | 143ms | 12212kb | C++20 | 5.0kb | 2024-07-13 16:56:27 | 2024-07-13 16:56:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;
struct L{
ll m, k;
L(){
}
L(ll n, ll k){
this->m = n;
this->k = k;
}
ll get(ll x){
return 0ll + m * x + k;
}
};
using piL = pair<ll,L>;
ll banana(L a, L b){
return (b.k - a.k + (a.m - b.m - 1)) / (a.m - b.m) ;
}
void solve(){
int n, m, s, t;
cin >> n >> m >> s >> t;
vector<int> h(n+1);
for(int i = 1;i <= n;i ++)
cin >> h[i];
vector<vector<int>> v(n+1);
for(int i = 0;i < m;i ++){
int a,b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
priority_queue<pii, vector<pii>, greater<pii>> pq;
vector<bool> vis(n+1);
vector<ll> d1(n+1, 1e11);
vector<ll> d2(n+1, 1e11);
d1[s] = 0;
d2[t] = 0;
pq.emplace(0, s);
while(pq.size() > 0){
auto cur = pq.top();
pq.pop();
if(vis[cur.second])
continue;
vis[cur.second] = 1;
for(int i : v[cur.second]){
if(vis[i])
continue;
ll nx = cur.first + (h[i] - h[cur.second]) * (h[i] - h[cur.second]);
if(nx < d1[i]){
d1[i] = nx;
pq.emplace(nx, i);
}
}
}
vis.clear();
vis.resize(n+1);
pq.emplace(0, t);
while(pq.size() > 0){
auto cur = pq.top();
pq.pop();
if(vis[cur.second])
continue;
vis[cur.second] = 1;
for(int i : v[cur.second]){
if(vis[i])
continue;
ll nx = cur.first + (h[i] - h[cur.second]) * (h[i] - h[cur.second]);
if(nx < d2[i]){
d2[i] = nx;
pq.emplace(nx, i);
}
}
}
ll ans = 2*d1[t];
for(int i = 1;i <= n;i ++){
if(i == s || i == t){
ll rec = 1e11;
for(int it : v[i]){
if(i == s)
rec = min(rec, d2[it]*2);
else
rec = min(rec, d1[it]*2);
}
ans = min(ans, rec);
continue;
}
deque<pair<int, L>> dq;
set<pii> st;
for(int it : v[i])
st.emplace(h[it], it);
map<int,int> mp;
ll rec = 1e11;
for(pii i : st){
if(mp[i.first])
continue;
mp[i.first] = 1;
L nx(-2 * i.first, 2*d2[i.second] + i.first * i.first);
if(dq.size() == 0){
dq.emplace_back(1e9, nx);
continue;
}
while(dq.size() > 1){
auto cur = dq.back();
ll tmp = banana(cur.second, nx);
if(tmp < dq[dq.size()-2].first){
dq[dq.size()-2].first = banana(nx, dq[dq.size()-2].second);
dq.pop_back();
}else{
break;
}
}
ll x = banana(nx, dq.back().second);
dq.back().first = x;
dq.emplace_back(1e9, nx);
}
for(int p : v[i]){
int l = -1;
int r = dq.size();
while(r - l > 1){
int mid = (r + l) / 2;
if(dq[mid].first > h[p]){
r = mid;
}else{
l = mid;
}
}
rec = min(rec, 2*d1[p] + h[p] * h[p] + dq[r].second.get(h[p]));
}
ans = min(rec, ans);
}
cout << double(ans) / 2 << "\n";
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4020kb
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: 3728kb
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: 1ms
memory: 3780kb
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: 3780kb
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: 143ms
memory: 12212kb
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:
-2.43166e+12
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '-2431660000000.0000000', error = '2431660000000.0000000'