QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#475890 | #5540. City Hall | Thirvin | Compile Error | / | / | C++20 | 5.0kb | 2024-07-13 16:58:52 | 2024-07-13 16:58:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
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 << fixed << setprecision(15)
cout << double(ans) / 2 << "\n";
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
Details
answer.code: In function ‘void solve()’: answer.code:143:42: error: expected ‘;’ before ‘cout’ 143 | cout << fixed << setprecision(15) | ^ | ; 144 | cout << double(ans) / 2 << "\n"; | ~~~~