QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339295 | #5540. City Hall | AllSolvedin1557# | WA | 1ms | 7936kb | C++20 | 2.3kb | 2024-02-26 23:07:15 | 2024-02-26 23:07:16 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll INF = 1e18;
struct linecontainer{
vector<pll>v;
ll cnt=0;
void clear() {
v.clear(); cnt=0;
}
void insert(pll p) {
while(v.size()>=2&&(__int128)(v.back().se-v[v.size()-2].se)*(v[v.size()-2].fi-p.fi) >= (__int128)(p.se-v[v.size()-2].se)*(v[v.size()-2].fi-v.back().fi) ) v.pop_back();
v.push_back(p);
}
ll f(pll p,ll x) { return p.fi*x+p.se; }
ll query(ll x)
{
while(cnt+1<v.size()&&f(v[cnt],x)>f(v[cnt+1],x)) cnt++;
return f(v[cnt],x);
}
}CHT;
ll dist[2][100005],n;
ll H[100005];
pll E[200005];
vector<ll>v[100005];
ll f(ll x,ll y) { return (H[x]-H[y])*(H[x]-H[y]); }
void dijk(ll s,ll t)
{
fill(dist[t]+1,dist[t]+1+n,INF);
dist[t][s]=0;
priority_queue<pll,vector<pll>,greater<pll> > pq;
pq.push({0,s});
while(!pq.empty())
{
pll p=pq.top(); pq.pop();
if(p.fi>dist[t][p.se]) continue;
for(auto i:v[p.se])
{
pll q={p.fi+f(i,p.se),i};
if(dist[t][q.se]>q.fi)
{
dist[t][q.se]=q.fi;
pq.push(q);
}
}
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
ll m,S,T,ans=INF;
cin>>n>>m>>S>>T;
for(ll i=1;i<=n;i++) cin>>H[i], H[i]*=2;
for(ll i=1;i<=m;i++)
{
cin>>E[i].fi>>E[i].se;
v[E[i].fi].push_back(E[i].se); v[E[i].se].push_back(E[i].fi);
}
dijk(S,0); dijk(T,1);
ans=dist[0][T];
for(ll k=1;k<=n;k++)
{
vector<pll>line,target; CHT.clear();
for(auto a:v[k]) line.push_back({-H[a],dist[1][a]+H[a]*H[a]/2}), target.push_back({H[a],dist[0][a]+H[a]*H[a]/2});
sort(line.begin(),line.end(),greater<pll>()); sort(target.begin(),target.end());
for(ll i=0;i<line.size();i++)
{
if(i+1<line.size()&&line[i].fi==line[i+1].fi) continue;
CHT.insert(line[i]);
}
for(ll i=0;i<target.size();i++)
ans=min(ans,CHT.query(target[i].fi)+target[i].se);
}
ans/=2;
cout<<ans/2<<'.'<<ans%2*5;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7692kb
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: 1ms
memory: 7852kb
input:
5 5 1 5 1 2 10 10 4 1 2 2 3 2 4 3 5 4 5
output:
3.0
result:
ok found '3.0000000', expected '3.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7932kb
input:
5 4 1 4 8 8 8 8 100 1 2 2 3 3 4 4 5
output:
0.0
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7936kb
input:
2 1 1 2 0 100000 1 2
output:
10000000000.0
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '10000000000.0000000', error = '10000000000.0000000'