QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#624301#5540. City HallOlderaTL 266ms26800kbC++175.7kb2024-10-09 15:29:152024-10-09 15:29:15

Judging History

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

  • [2024-10-09 15:29:15]
  • 评测
  • 测评结果:TL
  • 用时:266ms
  • 内存:26800kb
  • [2024-10-09 15:29:15]
  • 提交

answer

#pragma GCC optimize ("O3")

//#incluse <bits/stdc++.h>

#include <iostream>     // Input/output stream objects
#include <fstream>      // File stream objects
#include <sstream>      // String stream objects
#include <iomanip>      // Input/output manipulators
#include <string>       // String class and functions
#include <vector>       // Dynamic array
#include <list>         // Doubly linked list
#include <set>          // Set container
#include <map>          // Map container
#include <queue>        // Queue container
#include <stack>        // Stack container
#include <algorithm>    // Algorithms on sequences (e.g., sort, find)
#include <cmath>        // Mathematical functions
#include <ctime>        // Date and time functions
#include <cstdlib>      // General purpose functions (e.g., memory management)
#include <cstring>      // C-style string functions
#include <cctype>       // Character classification functions
#include <cassert>      // Assert function for debugging
#include <exception>    // Standard exceptions
#include <functional>   // Function objects
#include <iterator>     // Iterator classes
#include <limits>       // Numeric limits
#include <locale>       // Localization and internationalization
#include <numeric>      // Numeric operations (e.g., accumulate)
#include <random>       // Random number generators
#include <stdexcept>    // Standard exception classes
#include <typeinfo>     // Runtime type information
#include <utility>      // Utility components (e.g., std::pair)
#include <tuple>
#include <cstdio>
#include <bitset>

using namespace std;

// ************ Setting up  ************
#define FPTU ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define BUG(x) {cerr << #x << " = " << x << endl;}
#define pii pair<int,int>
#define pip pair<int,pii>
#define ppi pair<pii,int>
#define ll  long long
#define ull unsigned long long
#define usi unsigned int
#define pll pair<ll,ll>
#define plp pair<ll,pll>
#define ppl pair<pll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define oo 1000111000
#define ooo 1000111000111000111
#define inf 0x3f //4557430888798830399
#define fi first
#define se second
#define vt vector
#define pb push_back
#define all(arr) arr.begin(),arr.end()
#define bit(n, i) (((n) >> (i)) & 1)
#define db(x) cerr << #x << " = " << (x) << '\n';

ll rand_num(ll a,ll b) {
    random_device rd; mt19937 mt(rd()); uniform_int_distribution<ll> dist(a,b);
    return dist(mt);
}

int mod=1e9+7; // MODDDDDDDDDDDDD

template <typename T> void minimize(T &a, T b){ if(a>b)  a=b; }
template <typename T> void maximize(T &a, T b){ if(a<b)  a=b; }
template <typename T> void add(T &a, T b){ a+=b; if(a>=mod) a-=mod; }
template <typename T> T gcd(T a, T b){
    while(a!=0&&b!=0) if(a>b) a%=b; else b%=a; return a+b; }
void read_file()
{
    freopen("sample.inp","r",stdin);
    freopen("sample.out","w",stdout);
}
// =========> <3 VietHai1709 <3  <=========
struct line{
    ll a,b;
    line(ll x=0,ll y=ooo)
    {
        a=x; b=y;
    }
    ll get(ll x)
    {
        return a*x+b;
    }

};
struct LichaoTree{
    // get max => lower convexhull
    // get min => upper convexhull

    vt<line> F;
    int n;
    LichaoTree(int _){
        n=_;
        F.resize(n<<2);
    }
    void reset(){
        F.clear();
        F.resize(n<<2);
    }
    void add(int id,int l,int r,line cur)
    {
        int mid=(l+r)>>1;
        bool lef = cur.get(l) < F[id].get(l);
        bool mi = cur.get(mid) < F[id].get(mid);
        if(mi) swap(F[id],cur);
        if(l==r) return;
        if(lef==mi) add(id*2+1,mid+1,r,cur);
        else add(id*2,l,mid,cur);
    }

    ll query(int id,int l,int r,ll x)
    {
        int mid=(l+r)>>1;
        if(l==r) return F[id].get(x);
        ll ans=F[id].get(x);
        if(x<=mid) minimize(ans, query(id*2,l,mid,x));
        else minimize(ans, query(id*2+1,mid+1,r,x));
        return ans;
    }
    
};
void Dijktra(int st,vt<vt<pair<int,ll>>> Edge, vt<ll> &dis)
{
    dis[st]=0;
    priority_queue<pli,vt<pli>,greater<pli>> pq;
    pq.push({0,st});
    while(!pq.empty())
    {
        pli k=pq.top(); pq.pop();
        int u = k.se;
        ll w = k.fi;
        
        if (w > dis[u]) continue;

        for(auto &[v,x]: Edge[u]) {
           if (dis[v] > w + x) {
               dis[v] = x + w;
               pq.push({dis[v], v});
           }
        }
    }
}
ll dis(ll a,ll b){
    return (a-b)*(a-b);
}
bool cmp(pair<int,ll> &a, pair<int,ll> &b){
    return a.se<b.se;
}
void Minnnnnnn()
{
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    vt<ll> h(n+1);
    for(int i=1;i<=n;i++) cin>>h[i];
    vt<vt<pair<int,ll>> > ke(n+1);
    while(m--){
        int u,v;
        cin>>u>>v;
        ll w=dis(h[u],h[v]);
        ke[u].pb({v,w});
        ke[v].pb({u,w});
    }
    vt<ll> F(n+1,ooo);
    vt<ll> G(n+1,ooo);
    Dijktra(s, ke, F);
    Dijktra(t, ke, G);
    
    ll ans=ooo;
    for(auto &[u,_]:ke[s]) ans=min(ans,G[u]*2);
    for(auto &[u,_]:ke[t]) ans=min(ans,F[u]*2);
    //cout<<setprecision(2)<<fixed<<ans/2.0<<'\n';
    int mx=100000;
    for(int i=1;i<=n;i++) if(i!=s && i!=t){
        LichaoTree myLichao(mx);
        for(auto &[u,_]:ke[i]){
            myLichao.add(1, 1, mx, line(h[u]*-2,h[u]*h[u]+G[u]*2));
        }
        for(auto &[u,_]:ke[i]){
            ans=min(ans,F[u]*2+h[u]*h[u]+myLichao.query(1, 1, mx, h[u]));
        }
    }
    cout<<setprecision(2)<<fixed<<ans/2.0;
}


int main(){
    
    FPTU; //fast
    //read_file();
    
    int __=1;
    //cin>>__;
    for(int _=1;_<=__;_++)
    {
        Minnnnnnn();
    }
    cerr << "Time elapsed: " << TIME << " s.\n";

    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

4.50

result:

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

Test #2:

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

input:

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

output:

3.00

result:

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

Test #3:

score: 0
Accepted
time: 4ms
memory: 10372kb

input:

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

output:

0.00

result:

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

Test #4:

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

input:

2 1 1 2
0 100000
1 2

output:

0.00

result:

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

Test #5:

score: 0
Accepted
time: 266ms
memory: 26800kb

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.00

result:

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

Test #6:

score: 0
Accepted
time: 245ms
memory: 22020kb

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.00

result:

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

Test #7:

score: -100
Time Limit Exceeded

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:


result: