QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#704574 | #5540. City Hall | MeatInTheMiddle | WA | 132ms | 15336kb | C++20 | 3.6kb | 2024-11-02 20:15:41 | 2024-11-02 20:15:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define allr(x) x.rbegin(), x.rend()
#define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define endl "\n"
#define sp " "
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rz resize
#define sz(a) (int)(a.size())
#define clr(a) a.clear()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef tuple<int, int, int> tpi;
typedef tuple<ll, ll, ll> tpl;
typedef pair<double, ll> pdl;
typedef pair<double, int> pdi;
const int dx[] = {1,-1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
const ll MOD = 1e9+7;
const ll INF = 1e12;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MAX = 101010; // PLZ CHK!
struct LiChao {
struct Line {
ll a,b;
ll get(ll x) {return a*x+b;}
};
struct Node {
int l,r;
ll s,e;
Line line;
};
vector<Node> tree;
// For max query, initialize -LINF instead
void init(ll s, ll e) { tree.pb({-1,-1,s,e,{0,LINF}}); }
void upd(int node, Line v) {
auto [l,r,s,e,curl]=tree[node];
ll m=(s+e)>>1;
Line lo=curl, hi=v;
if (lo.get(s)>hi.get(s)) swap(lo,hi);
if (lo.get(e)<=hi.get(e)) {
tree[node].line=lo;
return;
}
if (lo.get(m)<=hi.get(m)) {
tree[node].line=lo;
if (tree[node].r==-1) {
tree[node].r=sz(tree);
tree.pb({-1,-1,m+1,e,{0,LINF}});
}
upd(tree[node].r,hi);
}
else {
tree[node].line=hi;
if (tree[node].l==-1) {
tree[node].l=sz(tree);
tree.pb({-1,-1,s,m,{0,LINF}});
}
upd(tree[node].l,lo);
}
}
ll qry(int node, ll x) {
if (node==-1) return LINF;
auto [l,r,s,e,curl]=tree[node];
ll m=(s+e)>>1;
if (x<=m) return min(tree[node].line.get(x), qry(tree[node].l,x));
else return min(tree[node].line.get(x), qry(tree[node].r,x));
}
};
int N,M,S,T;
ll H[MAX];
vector<ll> DS,DT;
vector<int> G[MAX];
void dij(int s, vector<ll> &d) {
d.assign(N+1,LINF);
priority_queue<pll,vector<pll>,greater<pll>> pq;
d[s]=0;
pq.push({d[s],s});
while (!pq.empty()) {
auto [dst,cur]=pq.top(); pq.pop();
if (dst!=d[cur]) continue;
for (int nxt:G[cur]) {
ll cst=(H[cur]-H[nxt])*(H[cur]-H[nxt]);
if (d[nxt]>d[cur]+cst) {
d[nxt]=d[cur]+cst;
pq.push({d[nxt],nxt});
}
}
}
}
int main() {
fio();
cin>>N>>M>>S>>T;
for (int i=1; i<=N; i++) {
cin>>H[i];
H[i]*=2;
}
for (int i=0; i<M; i++) {
int u,v; cin>>u>>v;
G[u].pb(v), G[v].pb(u);
}
dij(S,DS),dij(T,DT);
ll ans=DS[T];
for (int v:G[S]) ans=min(ans, DT[v]);
for (int v:G[T]) ans=min(ans, DS[v]);
for (int u=1; u<=N; u++) {
if (u==S || u==T) continue;
LiChao li; li.init(-1e18,1e18);
for (int v:G[u]) li.upd(0,{-H[v],H[v]*H[v]/2+DT[v]});
for (int v:G[u]) {
ll t=li.qry(0,H[v])+H[v]*H[v]/2+DS[v];
ans=min(ans, t);
}
}
cout<<fixed; cout.precision(10);
cout<<1.0*ans/4.0;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3728kb
input:
5 6 1 3 5 100 8 2 10 1 2 2 3 2 5 1 4 4 5 3 5
output:
4.5000000000
result:
ok found '4.5000000', expected '4.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5924kb
input:
5 5 1 5 1 2 10 10 4 1 2 2 3 2 4 3 5 4 5
output:
3.0000000000
result:
ok found '3.0000000', expected '3.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5828kb
input:
5 4 1 4 8 8 8 8 100 1 2 2 3 3 4 4 5
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
2 1 1 2 0 100000 1 2
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 72ms
memory: 15060kb
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.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 57ms
memory: 9264kb
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.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: 0
Accepted
time: 132ms
memory: 14224kb
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:
1019365473.0000000000
result:
ok found '1019365473.0000000', expected '1019365473.0000000', error '0.0000000'
Test #8:
score: 0
Accepted
time: 131ms
memory: 15328kb
input:
100000 200000 21412 38673 24050 75090 3692 20770 26840 57646 61096 3013 66291 73437 83126 67768 92979 69169 9389 70447 17151 74737 33407 3128 78504 52736 45853 27090 64395 24808 83577 24168 38576 37445 71022 40066 34908 90579 58370 31436 69812 39811 83370 50254 6518 72740 79316 67247 22759 65630 564...
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #9:
score: -100
Wrong Answer
time: 118ms
memory: 15336kb
input:
100000 200000 75283 45047 38593 5224 81049 28255 11324 43744 51172 60916 67783 62336 96782 50029 48743 18780 32756 4774 32484 95733 17336 38046 98145 49655 68352 58308 21594 64540 11719 57827 30130 70076 95133 29886 93864 22677 28498 60413 44567 78935 64952 88954 85786 34019 75159 69192 15108 54645 ...
output:
449627765.0000000000
result:
wrong answer 1st numbers differ - expected: '6010044.5000000', found: '449627765.0000000', error = '73.8127181'