QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720952 | #5540. City Hall | Suhy# | WA | 136ms | 16688kb | C++14 | 2.7kb | 2024-11-07 14:48:08 | 2024-11-07 14:48:08 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define lb(x) ((x) & (-(x)))
#define pii pair<int, int>
#define st first
#define nd second
#define ld long double
using namespace std;
int read()
{
int x = 0, c = 0;
while('0' > c || c > '9')
c = getchar();
while('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x;
}
const int maxn = 100005;
int n, m, s, t;
ll h[maxn];
vector <int> pic[maxn];
ll sps[maxn], spt[maxn];
priority_queue <pii, vector<pii>, greater<pii> > que;
int vis[maxn];
ll calc(int x, int y)
{return (h[x] - h[y]) * (h[x] - h[y]);}
void dij(ll *sp, int s)
{
que.push({0, s});
while(que.size())
{
int in = que.top().nd;
que.pop();
if(vis[in]) continue;
vis[in] = 1;
for(int i : pic[in])
{
if(!vis[i] && (!sp[i] || (sp[i] > sp[in] + calc(in, i))))
{
sp[i] = sp[in] + calc(in, i);
que.push({sp[i], i});
}
}
}
memset(vis, 0, sizeof vis);
}
pair <ld, ld> q[maxn];
int l, r;
ld pnt[maxn];
ld getp(pair <ld, ld> a, pair <ld, ld> b)
{
return (b.nd - a.nd) / (a.st - b.st);
}
ld getans(pair <ld, ld> l, ll x)
{
return l.st * x + l.nd;
}
ld ans = 100000000000000000LL;
void sol(ll *a, ll *b)
{
for(int i = 1; i <= n; i ++)
{
if(i == s || i == t)
continue;
l = 1, r = 0;
for(int j : pic[i])
{
//cout<<j<<endl;
while(r - l + 1 > 1 && pnt[l + 1] < h[j])
l ++;
if(r >= l) ans = min(ans, getans(q[l], h[j]) + 0.5 * h[j] * h[j] + b[j]);
pair <ld, ld> lin = {-h[j], a[j] + 0.5 * h[j] * h[j]};
while(r - l + 1 > 1)
{
ld npt = getp(q[r], lin);
if(npt < pnt[r]) r --;
else break;
}
q[++ r] = lin;
pnt[r] = getp(lin, q[r - 1]);
}
}
}
bool _Cmp(int x, int y)
{return h[x] < h[y];}
int main()
{
cin>>n>>m>>s>>t;
for(int i = 1; i <= n; i ++)
h[i] = read();
for(int i = 1; i <= m; i ++)
{
int u = read();
int v = read();
pic[u].push_back(v);
pic[v].push_back(u);
}
dij(sps, s);
dij(spt, t);
for(int i = 1; i <= n; i ++)
sort(pic[i].begin(), pic[i].end(), _Cmp);
for(int i : pic[s])
ans = min(ans, (ld) spt[i]);
for(int i : pic[t])
ans = min(ans, (ld) sps[i]);
//cout<<ans<<endl;
sol(sps, spt);
sol(spt, sps);
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8972kb
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: 10508kb
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: 10320kb
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: 1ms
memory: 8420kb
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: 0
Accepted
time: 136ms
memory: 13124kb
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:
0
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 100ms
memory: 12048kb
input:
600 179700 396 574 83219 94660 9266 1939 32637 7117 33396 76947 42614 41001 87026 60210 25868 36044 35276 6147 36198 25195 50981 68230 32619 62563 28509 46643 43304 36195 99724 30903 77230 57923 36939 81397 17374 90947 48623 38120 48914 96481 98146 31707 9427 58735 82986 31328 94507 69081 51908 4188...
output:
0
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: -100
Wrong Answer
time: 101ms
memory: 16688kb
input:
100000 200000 66364 98254 48399 8344 35365 18555 95271 13113 75220 25062 73969 71647 58212 68205 36310 45496 6965 59960 71592 81323 44341 95796 61521 63298 77830 16145 73103 83477 85246 53680 67289 68475 64978 43576 18969 28023 22848 55164 31276 12825 70999 49142 77203 40134 88148 59337 2357 70519 8...
output:
8.76096e+09
result:
wrong answer 1st numbers differ - expected: '1019365473.0000000', found: '8760960000.0000000', error = '7.5945230'