QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722008#5540. City HallinfCraft#WA 296ms50848kbC++172.5kb2024-11-07 17:26:292024-11-07 17:26:30

Judging History

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

  • [2024-11-07 17:26:30]
  • 评测
  • 测评结果:WA
  • 用时:296ms
  • 内存:50848kb
  • [2024-11-07 17:26:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define fori(x, y) for (int i=(x);i<=(y);++i)
#define forj(x, y) for (int j=(x);j<=(y);++j)
#define fork(x, y) for (int k=(x);k<=(y);++k)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define debug(x) cerr << #x << " = " << x << endl

typedef long double ld;
const int N = 2e5+7;
ll h[N];
vector<pll> g[N];

bool vis[N][3];
ll dist[N][3];
struct Node {
    int u;
    ll dis;
    int fa;
    int layer;  // 在哪一层
    Node(int u, ld dis, int fa, int la): u(u), dis(dis), fa(fa), layer(la) {}
};
struct cmp {
    bool operator()(Node& n1, Node& n2) {
        return n1.layer == n2.layer ? n1.dis > n2.dis: n1.layer > n2.layer;
    }
};
void Dijkstra(int s, int n) {
    fori(1, n) {
        vis[i][0] = vis[i][1] = vis[i][2] = false;
        dist[i][0] = dist[i][1] = dist[i][2] = 1e18;
    }
    priority_queue<Node,vector<Node>,cmp> pri;
    pri.push(Node(s, 0, 0, 0));
    while (pri.size()) {
        auto no = pri.top();
        pri.pop();
        if (vis[no.u][no.layer]) continue;
        vis[no.u][no.layer] = true;
        dist[no.u][no.layer] = no.dis;
        // debug(no.u);
        // debug(no.dis);
        // debug(no.layer);

        if (no.layer == 1) {  // 刚刚转移下来
            for (auto [v, b]: g[no.u]) {
                if (vis[v][2]) continue;
                ll dis2 = (h[no.fa]-h[v])*(h[no.fa]-h[v]);
                pri.push(Node(v, no.dis+dis2, no.u, 2));
            }
            continue;
        }
        // 同一层
        for (auto [v, dis]: g[no.u]) {
            if (vis[v][no.layer]) continue;
            pri.push(Node(v, no.dis+dis, no.u, no.layer));
        }
        if (no.layer == 0) {  // 跳到下一层
            for (auto [v, b]: g[no.u]) {
                if (vis[v][1]) continue;
                pri.push(Node(v, no.dis, no.u, 1));
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m, s, t;
    cin >> n >> m >> s >> t;
    fori(1, n) cin >> h[i];
    fori(1, m) {
        int u, v;
        cin >> u >> v;
        ll dis = (h[u]-h[v])*(h[u]-h[v])*2;
        g[u].push_back({v, dis});
        g[v].push_back({u, dis});
    }
    Dijkstra(s, n);
    cout << fixed << setprecision(10);
    cout << min({dist[t][0]/2.0l, dist[t][1]/2.0l, dist[t][2]/2.0l}) << endl;
    // cout << dist[t][2]/2.0l << endl;
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 10328kb

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: 10276kb

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: 2ms
memory: 12000kb

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: 203ms
memory: 44908kb

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: 183ms
memory: 46972kb

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: 283ms
memory: 49072kb

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: 253ms
memory: 50180kb

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: 0
Accepted
time: 266ms
memory: 50848kb

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:

6010044.5000000000

result:

ok found '6010044.5000000', expected '6010044.5000000', error '0.0000000'

Test #10:

score: 0
Accepted
time: 296ms
memory: 50404kb

input:

100000 200000 50293 63302
78731 76313 68601 46867 82806 57914 88495 43602 96202 44956 6593 96560 38650 61918 69911 48730 38668 8874 44449 25084 68496 18095 74789 52252 36631 68127 37908 63134 61923 68030 83186 81174 68083 78584 33622 74426 34099 32484 80162 10371 55894 65989 6374 76587 87442 50870 3...

output:

1926329544.0000000000

result:

ok found '1926329544.0000000', expected '1926329544.0000000', error '0.0000000'

Test #11:

score: -100
Wrong Answer
time: 275ms
memory: 49616kb

input:

100000 200000 81105 2350
9856 14867 98102 45742 76449 20173 90566 85519 8273 40573 98784 21094 38040 75579 21248 37555 32846 95358 92476 76093 99209 81806 76912 80248 93022 87883 85938 20897 20561 19811 59752 42986 36831 82149 73443 66562 96573 52522 68268 28832 46601 39663 61155 69950 13823 36697 9...

output:

2597874388.0000000000

result:

wrong answer 1st numbers differ - expected: '1746699958.0000000', found: '2597874388.0000000', error = '0.4873043'