QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354622#5540. City HallSolitaryDream#WA 135ms20088kbC++172.3kb2024-03-15 19:08:192024-03-15 19:08:19

Judging History

你现在查看的是最新测评结果

  • [2024-03-15 19:08:19]
  • 评测
  • 测评结果:WA
  • 用时:135ms
  • 内存:20088kb
  • [2024-03-15 19:08:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
typedef long long ll;
const int N=1e5+50;
const ll INF=1e18;
vector<int> E[N];
ll h[N];
int n;
void init(int s,ll *dis) {
    priority_queue<pair<int,int>> Q;
    FOR(i,1,n) dis[i]=INF;
    dis[s]=0;
    Q.push({0,s});
    while(Q.size()) {
        auto [d,x]=Q.top();
        Q.pop();
        if(-d>dis[x]) continue;
        for(auto y: E[x]) {
            ll v=-d+(h[y]-h[x])*(h[y]-h[x]);
            if(v<dis[y]) {
                dis[y]=v;
                Q.push({-v,y});
            }
        }
    }
}
ll dis1[N],dis2[N];
struct seg {
    ll k,b;
    ll value(int x) const{
        return k*x+b;
    }
};
struct node {
    int tag;
    seg s;
} T[N<<2];
#define ls p<<1
#define rs p<<1|1
#define lson L,mid,ls
#define rson mid+1,R,rs
void Down(int p) {
    if(T[p].tag) {
        T[ls]={1,{0,INF}};
        T[rs]={1,{0,INF}};
        T[p].tag=0;
    }
}
void ins(int L,int R,int p,seg s) {
    int mid=L+R>>1;
    if(s.value(mid)<T[p].s.value(mid)) swap(T[p].s,s);
    if(L==R) return ;
    Down(p);
    if(s.value(L)<T[p].s.value(L)) ins(lson,s);
    if(s.value(R)<T[p].s.value(R)) ins(rson,s);
}
ll qry(int L,int R,int p,int x) {
    if(L==R) return T[p].s.value(x);
    Down(p);
    int mid=L+R>>1;
    if(x<=mid) return min(T[p].s.value(x),qry(lson,x));
    else return min(T[p].s.value(x),qry(rson,x));
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(9);
    int m,s,t;
    cin >> n >> m >> s >> t;
    FOR(i,1,n) cin >> h[i];
    FOR(i,1,m) {
        int u,v;
        cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
    }
    init(s,dis1);
    init(t,dis2);
    int mx=1e5;
    double res=dis1[t];
    for(auto j: E[s]) {
        res=min<double>(res,dis2[j]);
    }
    for(auto j: E[t]) {
        res=min<double>(res,dis1[j]);
    }
    FOR(i,1,n) {
        T[1]={1,{0,INF}};
        for(auto j: E[i]) {
            ins(0,mx,1,{-h[j]*2,dis1[j]*2+h[j]*h[j]});
        }
        for(auto j: E[i]) {
            res=min(res,0.5*(dis2[j]*2+h[j]*h[j]+qry(0,mx,1,h[j])));
        }
    }
    cout << res << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 13484kb

input:

5 6 1 3
5 100 8 2 10
1 2
2 3
2 5
1 4
4 5
3 5

output:

4.500000000

result:

ok found '4.5000000', expected '4.5000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 2ms
memory: 13056kb

input:

5 5 1 5
1 2 10 10 4
1 2
2 3
2 4
3 5
4 5

output:

3.000000000

result:

ok found '3.0000000', expected '3.0000000', error '0.0000000'

Test #3:

score: 0
Accepted
time: 2ms
memory: 12148kb

input:

5 4 1 4
8 8 8 8 100
1 2
2 3
3 4
4 5

output:

0.000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 12812kb

input:

2 1 1 2
0 100000
1 2

output:

0.000000000

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #5:

score: -100
Wrong Answer
time: 135ms
memory: 20088kb

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:

-4259252235.000000000

result:

wrong answer 1st numbers differ - expected: '0.0000000', found: '-4259252235.0000000', error = '4259252235.0000000'