QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#482883#5540. City HallkarunaWA 176ms17432kbC++202.2kb2024-07-17 23:57:572024-07-17 23:57:58

Judging History

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

  • [2024-07-17 23:57:58]
  • 评测
  • 测评结果:WA
  • 用时:176ms
  • 内存:17432kb
  • [2024-07-17 23:57:57]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

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

const int SZ = 202020;

int n, m, S, T, h[SZ];
vector<int> g[SZ];

ll ds[2][SZ];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	cin >> n >> m >> S >> T;
	--S; --T;
	
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		g[u - 1].push_back(v - 1);
		g[v - 1].push_back(u - 1);
	}

	for (int t = 0; t < 2; t++) {
		priority_queue<pll> pq;
		for (int i = 0; i < n; i++) {
			ds[t][i] = 1e18;
		}
		pq.push({0, t == 0 ? S : T});
		ds[t][t == 0 ? S : T] = 0;

		while (!pq.empty()) {
			auto [d, v] = pq.top();
			pq.pop();

			if (ds[t][v] != -d) continue;
			for (int x : g[v]) {
				ll w = 1ll * (h[v] - h[x]) * (h[v] - h[x]);
				if (ds[t][x] > ds[t][v] + w) {
					ds[t][x] = ds[t][v] + w;
					pq.push({-ds[t][x], x});
				}
			}
		}
	}

	ll ans = 9e18;
	for (int v = 0; v < n; v++) {
		vector<pll> cht;

		int sz = g[v].size();
		int ord[sz];
		iota(ord, ord + sz, 0);
		sort(ord, ord + sz, [&](int i, int j) {
			return h[g[v][i]] < h[g[v][j]];
		});

		for (int i = 0; i < sz; i++) {
			int x = g[v][ord[i]];

			ll e = -2 * h[x];
			ll f = 1ll * h[x] * h[x] + 2 * ds[1][x];

			if (!cht.empty() && cht.back().ff == e) {
				if (cht.back().ss < f) {
					f = cht.back().ss;
				}
				cht.pop_back();
			}

			while (cht.size() >= 2) {
				auto [a, b] = cht[cht.size() - 2];
				auto [c, d] = cht.back();
				
				if ((__int128)(c - e) * (d - b) >= (__int128)(a - c) * (f - d)) cht.pop_back();
				else break;
			}
			cht.push_back({e, f});
		}

		int pos = 0;

		for (int i = 0; i < sz; i++) {
			int x = g[v][ord[i]];

			while (pos < (int)cht.size() - 1) {
				auto [a, b] = cht[pos];
				auto [c, d] = cht[pos + 1];

				if ((__int128)x * (a - c) >= (d - b)) ++pos;
				else break;
			}
			ans = min(ans, cht[pos].ff * h[x] + cht[pos].ss + 1ll * h[x] * h[x] + 2 * ds[0][x]);
		}
	}

	for (int x : g[S]) ans = min(ans, 2 * ds[1][x]);
	for (int x : g[T]) ans = min(ans, 2 * ds[0][x]);

	cout << ans / 2 << (ans % 2 == 1 ? ".5" : ".0") << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3644kb

input:

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

output:

4.5

result:

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

Test #2:

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

input:

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

output:

3.0

result:

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

Test #3:

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

input:

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

output:

0.0

result:

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

Test #4:

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

input:

2 1 1 2
0 100000
1 2

output:

0.0

result:

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

Test #5:

score: 0
Accepted
time: 63ms
memory: 16384kb

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

result:

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

Test #6:

score: 0
Accepted
time: 56ms
memory: 9456kb

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

result:

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

Test #7:

score: 0
Accepted
time: 166ms
memory: 15060kb

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

result:

ok found '1019365473.0000000', expected '1019365473.0000000', error '0.0000000'

Test #8:

score: 0
Accepted
time: 176ms
memory: 16204kb

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

result:

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

Test #9:

score: 0
Accepted
time: 171ms
memory: 15124kb

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

result:

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

Test #10:

score: 0
Accepted
time: 164ms
memory: 14992kb

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

result:

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

Test #11:

score: 0
Accepted
time: 172ms
memory: 17432kb

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:

1746699958.0

result:

ok found '1746699958.0000000', expected '1746699958.0000000', error '0.0000000'

Test #12:

score: 0
Accepted
time: 96ms
memory: 11236kb

input:

100000 99999 27499 37224
50619 546 34928 55892 95127 83241 56167 1411 64361 65091 69529 50805 18412 47138 24827 35822 53959 16642 73725 69209 23403 82125 61003 92477 62663 85774 63819 6812 16133 1840 57576 82545 80082 56754 8563 84660 57303 4822 32294 74865 59555 75395 7723 97981 7648 7614 39995 373...

output:

1479019958.0

result:

ok found '1479019958.0000000', expected '1479019958.0000000', error '0.0000000'

Test #13:

score: 0
Accepted
time: 92ms
memory: 16040kb

input:

100000 99999 57731 17782
55279 41436 80902 80600 52243 45703 2077 49134 70618 42937 43184 28403 94643 67960 79090 32887 25781 5974 92239 19915 75711 29995 69433 77210 10715 1476 69243 17422 48392 62130 70202 86152 46473 68342 55024 12135 59955 12466 35433 70410 30778 17201 73299 49206 22581 40598 68...

output:

0.0

result:

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

Test #14:

score: 0
Accepted
time: 93ms
memory: 15696kb

input:

100000 99999 73910 93392
4580 92394 65741 34067 1188 10312 33818 93538 87742 1111 15249 59319 21489 41536 67159 80368 70337 71510 11825 37146 18247 31165 85234 45308 15731 10225 14274 82315 1863 67625 34018 45831 689 40731 74176 34334 70252 97644 93344 19553 54498 92189 83921 76131 84274 23497 64458...

output:

3378244.0

result:

ok found '3378244.0000000', expected '3378244.0000000', error '0.0000000'

Test #15:

score: -100
Wrong Answer
time: 0ms
memory: 3848kb

input:

100 183 81 44
0 0 0 4 8 4 0 0 0 0 4 4 4 4 0 4 4 0 4 0 4 0 0 6 4 0 0 0 4 4 4 4 4 4 0 0 0 5 0 2 4 0 0 6 4 6 4 4 0 4 4 4 0 4 0 4 0 4 0 0 0 7 0 0 0 0 4 4 4 4 0 0 4 0 0 4 0 4 0 0 0 0 0 0 4 0 4 0 4 4 0 0 3 0 1 1 0 0 7 4
66 97
46 99
7 64
87 90
3 66
25 64
64 68
64 72
67 87
26 66
5 62
52 87
8 64
33 87
73 87
...

output:

14.0

result:

wrong answer 1st numbers differ - expected: '13.5000000', found: '14.0000000', error = '0.0370370'