QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113827#5540. City HallPetroTarnavskyi#WA 3ms9564kbC++172.4kb2023-06-19 16:50:182023-06-19 16:50:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-19 16:50:19]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9564kb
  • [2023-06-19 16:50:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const LL LINF = 1e18;
const int N = 1 << 17;

LL h[N];
LL dist[2][N];
vector<int> g[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--;
	t--;
	FOR(i, 0, n) {
		cin >> h[i];
	}
	FOR(i, 0, m) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	FOR(it, 0, 2) {
		FOR(i, 0, N) {
			dist[it][i] = LINF;
		}
		priority_queue<pair<LL, int>> pq;
		int v0 = it == 0 ? s : t;
		dist[it][v0] = 0;
		pq.emplace(0, v0);
		while (!pq.empty()) {
			auto [d, v] = pq.top();
			pq.pop();
			d *= -1;
			if (d != dist[it][v]) {
				continue;
			}
			for (int to : g[v]) {
				LL nd = d + (h[to] - h[v]) * (h[to] - h[v]);
				if (nd < dist[it][to]) {
					dist[it][to] = nd;
					pq.emplace(-nd, to);
				}
			}
		}
	}
	LL ans = 2 * dist[0][t];
	FOR(v, 0, n) {
		vector<pair<LL, LL>> vec, convex;
		for (int j : g[v]) {
			vec.emplace_back(-2 * h[j], 2 * dist[1][j] + h[j] * h[j]);
		}
		sort(ALL(vec), [](pair<LL, LL> p1, pair<LL, LL> p2) {
			if (p1.first != p2.first) {
				return p1.first > p2.first;
			}
			return p1.second > p2.second;
		});
		for (auto [k, b] : vec) {
			if (SZ(convex) > 1) {
				auto [k1, b1] = convex[SZ(convex) - 2];
				auto [k2, b2] = convex.back();
				if (k == k2 || (k - k2) * (b2 - b1) <= (b2 - b) * (k1 - k2)) {
					convex.pop_back();
				}
			}
			convex.emplace_back(k, b);
		}
		for (int i : g[v]) {
			int l = 0, r = SZ(convex) - 1;
			while (r - l > 2) {
				int m1 = (l + r) / 2, m2 = m1 + 1;
				auto [k1, b1] = convex[m1];
				auto [k2, b2] = convex[m2];
				if (k1 * h[i] + b1 < k2 * h[i] + b2) {
					r = m2;
				}
				else {
					l = m1;
				}
			}
			LL cur = LINF;
			for (; l <= r; l++) {
				auto [k, b] = convex[l];
				cur = min(cur, k * h[i] + b);
			}
			ans = min(ans, 2 * dist[0][i] + h[i] * h[i] + cur);
		}
	}
	cout << ans / 2;
	if (ans & 1) {
		cout << ".5";
	}
	cout << "\n";
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 9092kb

input:

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

output:

3

result:

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

Test #3:

score: 0
Accepted
time: 3ms
memory: 9564kb

input:

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

output:

0

result:

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

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 8568kb

input:

2 1 1 2
0 100000
1 2

output:

10000000000

result:

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