Submission #963560

# Submission time Handle Problem Language Result Execution time Memory
963560 2024-04-15T10:06:00 Z IBory Cyberland (APIO23_cyberland) C++17
49 / 100
201 ms 10788 KB
#include "cyberland.h"
#include <bits/stdc++.h>
#define pii pair<ll, ll>
typedef long long ll;
using namespace std;

const int MAX = 100007;
vector<pii> G[MAX];
bool V[MAX];
ll D[MAX], LD[MAX];

double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
    for (int i = 0; i < N; ++i) G[i].clear();
	for (int i = 0; i < M; ++i) {
		G[x[i]].emplace_back(y[i], c[i]);
		G[y[i]].emplace_back(x[i], c[i]);
	}

	int ok = 0;
    memset(V, 0, sizeof(V));
	V[0] = 1;
	queue<int> Q;
	Q.push(0);
	while (!Q.empty()) {
		int cur = Q.front(); Q.pop();
		for (auto [next, _] : G[cur]) {
			if (V[next]) continue;
			if (next == H) {
				ok = 1;
				continue;
			}
			V[next] = 1;
			Q.push(next);
		}
	}

	if (!ok) return -1;

	memset(D, 0x3f, sizeof(D));
	priority_queue<pii, vector<pii>, greater<pii>> PQ;
	for (int i = 0; i < N; ++i) {
		if (!V[i] || (i && arr[i])) continue;
		PQ.emplace(D[i] = 0, i);
	}

	while (!PQ.empty()) {
		auto [cd, cur] = PQ.top(); PQ.pop();
		if (cd > D[cur]) continue;
		for (auto [next, nd] : G[cur]) {
			if (D[next] <= cd + nd) continue;
			D[next] = cd + nd;
			if (next == H) continue;
			PQ.emplace(D[next], next);
		}
	}

	memset(LD, 0x3f, sizeof(LD));
	PQ.emplace(LD[H] = 0, H);
	while (!PQ.empty()) {
		auto [cd, cur] = PQ.top(); PQ.pop();
		if (cd > LD[cur]) continue;
		for (auto [next, nd] : G[cur]) {
			if (LD[next] <= cd + nd) continue;
			PQ.emplace(LD[next] = cd + nd, next);
		}
	}

	double ans = D[H];
	if (K) {
		for (int i = 0; i < N; ++i) {
			if (arr[i] != 2 || !V[i]) continue;
			ll a = D[i], b = LD[i], c = 1e18;
			for (auto [next, nd] : G[i]) {
				if (next == H) continue;
				c = min(c, nd);
			}

			double cd = (double)a / 2.0, t = cd;
			for (int k = 1; k < min(100, K); ++k) {
				t = (t + 2LL * c) / 2.0;
			}
            cd = min(cd, t);
            cd += (double)b;

			ans = min(ans, cd);
		}
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 201 ms 5004 KB Correct.
2 Correct 194 ms 4692 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 22 ms 4444 KB Correct.
2 Correct 35 ms 4628 KB Correct.
3 Correct 26 ms 4444 KB Correct.
4 Correct 27 ms 4444 KB Correct.
5 Correct 31 ms 4444 KB Correct.
6 Correct 21 ms 5212 KB Correct.
7 Correct 32 ms 5208 KB Correct.
8 Correct 12 ms 5976 KB Correct.
9 Correct 49 ms 4444 KB Correct.
10 Correct 50 ms 4444 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4604 KB Correct.
2 Correct 27 ms 4444 KB Correct.
3 Correct 25 ms 4440 KB Correct.
4 Correct 50 ms 4444 KB Correct.
5 Correct 50 ms 4500 KB Correct.
6 Correct 7 ms 5212 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 9052 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 4700 KB Correct.
2 Correct 22 ms 4700 KB Correct.
3 Correct 22 ms 4696 KB Correct.
4 Correct 21 ms 5660 KB Correct.
5 Correct 34 ms 4444 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 22 ms 4720 KB Correct.
2 Correct 21 ms 4596 KB Correct.
3 Correct 38 ms 10788 KB Correct.
4 Correct 14 ms 5464 KB Correct.
5 Correct 35 ms 4440 KB Correct.
6 Correct 21 ms 4696 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 4700 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 4696 KB Wrong Answer.
2 Halted 0 ms 0 KB -