QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789613#5540. City HallFireball0424#WA 159ms141404kbC++143.9kb2024-11-27 21:09:532024-11-27 21:10:01

Judging History

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

  • [2024-11-27 21:10:01]
  • 评测
  • 测评结果:WA
  • 用时:159ms
  • 内存:141404kb
  • [2024-11-27 21:09:53]
  • 提交

answer

// #pragma GCC optimizer("Ofast")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
// #define int long long 
#define ld long double
#define ull unsigned long long 
#define fr first
#define fi first
#define sc second
#define se second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
//#define sz(x) (int)x.size()
using namespace std;

#ifndef fireball
#define tofu ios::sync_with_stdio(0); cin.tie(0);
#else
#define tofu freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif 

void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}

#define ll long long 

const ll INF = 1ll << 60;
const int N = 1e5 + 5;
struct line{
    ll m, k;
    ll val(ll x){
        return 1ll * m * x + k;
    }
};
struct seg{
    int l, r, m;
    line li = {0, INF};
    seg* ch[2]={NULL, NULL};
    void insert(line _li){
        if(l == r){
            if(li.val(m) > _li.val(m)) swap(li,_li);//
            return;
        }
        if(_li.val(m) < li.val(m)) swap(_li,li);
        if(li.m <= _li.m){
            if(!ch[0]) ch[0] = new seg(l,m);
            ch[0]->insert(_li);
        }
        else{
            if(!ch[1]) ch[1] = new seg(m+1,r);
            ch[1]->insert(_li);
        }
    }
    ll query(ll p){
        if(l == r) return li.val(p);
        if(p <= m and ch[0]) return min(li.val(p),ch[0]->query(p));
        else if(p > m and ch[1]) return min(li.val(p),ch[1]->query(p));
        else return li.val(p);
    }
    seg(int _l,int _r){
        l=_l,r=_r;
        m=l+r>>1;
    }
};

signed main(){
    tofu;
    int n, m, S, T;
    cin >> n >> m >> S >> T;

    ll ans = INF;

    int h[n + 1] = {};
    for(int i = 1; i <= n; ++i) cin >> h[i];
    vector<int> g[n + 1];
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
        if(x == S and y == T) ans = 0;
        if(x == T and y == S) ans = 0;
    }

    vector<ll> ds(n + 1, INF), dt(n + 1, INF);
    vector<int> vs(n + 1, 0), vt(n + 1, 0);
    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > q;

    ds[S] = 0;
    q.push({0, S});
    while(!q.empty()){
        int u = q.top().se;
        q.pop();
        if(vs[u]) continue;
        vs[u] = 1;
        for(int i : g[u]){
            if(ds[i] > ds[u] + 1ll * (h[i] - h[u]) * (h[i] - h[u])){
                ds[i] = ds[u] + 1ll * (h[i] - h[u]) * (h[i] - h[u]);
                q.push({ds[i], i});
            }
        }
    }

    dt[T] = 0;
    q.push({0, T});
    while(!q.empty()){
        int u = q.top().se;
        q.pop();
        if(vt[u]) continue;
        vt[u] = 1;
        for(int i : g[u]){
            if(dt[i] > dt[u] + 1ll * (h[i] - h[u]) * (h[i] - h[u])){
                dt[i] = dt[u] + 1ll * (h[i] - h[u]) * (h[i] - h[u]);
                q.push({dt[i], i});
            }
        }
    }

    // for(int i = 1; i <= n; ++i) cout << ds[i] << ' ';
    // db();
    // for(int i = 1; i <= n; ++i) cout << dt[i] << ' ';
    // db();

    
    ld mod = 0.0;
    for(int x = 1; x <= n; ++x){
        seg *rt_s = new seg(0, N);
        seg *rt_t = new seg(0, N);
        for(int i : g[x]){
            ll tmp = 2 * ds[i] + rt_s -> query(h[i]) + h[i] * h[i];
            ans = min(ans, tmp);


            ll a = -2 * h[i];
            ll b = h[i] * h[i] + 2 * dt[i];
            //db(a, b);
            rt_s -> insert({a, b});
        }

        for(int i : g[x]){
            ll tmp = 2 * dt[i] + rt_t -> query(h[i]) + h[i] * h[i];
            // db(x, i, res.se, res.fi, tmp);
            ans = min(ans, tmp);


            ll a = -2 * h[i];
            ll b = h[i] * h[i] + 2 * ds[i];
            // db(a, b);
            rt_t -> insert({a, b});
        }
    }
    
    mod = ans;
    mod *= 0.5;
    cout << fixed << setprecision(8) << mod << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4.50000000

result:

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

Test #2:

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

input:

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

output:

3.00000000

result:

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

Test #3:

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

input:

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

output:

0.00000000

result:

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

Test #4:

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

input:

2 1 1 2
0 100000
1 2

output:

0.00000000

result:

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

Test #5:

score: -100
Wrong Answer
time: 159ms
memory: 141404kb

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:

-8560131125.00000000

result:

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