Submission #984915

# Submission time Handle Problem Language Result Execution time Memory
984915 2024-05-17T08:16:09 Z javotaz Cyberland (APIO23_cyberland) C++17
49 / 100
199 ms 15632 KB
// In the Name of Allah

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

#pragma GCC optimize("Ofast,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")

typedef long long ll;
typedef pair<double, int> pd;

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()

const int N = 1e5 + 12, K = 76;
vector<pii> g[N];
int n, m, k, h, a[N];
double ans;
bool mrk[N][K], t[N]; 

void dfs(int u) {
	t[u] = true;
	if (u == h)
		return;
	for (auto i: g[u])
		if (!t[i.F])
			dfs(i.F);
}

void find_ans() {
	dfs(0);
	ans = 1e18;
	if (!t[h]) { 
		ans = -1;
		return;
	}
	priority_queue<pd, vector<pd>, greater<pd>> q;
	q.push({0, 0});
	for (int i = 1; i < n; i++)
		if (!a[i] && t[i])
			q.push({0, i});
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		int u = tmp.S % n, ck = tmp.S / n;
		double w = tmp.F;
		if (u == h) {
			ans = min(ans, w);
			mrk[u][ck] = true;
		}
		if (mrk[u][ck])
			continue;
		mrk[u][ck] = true;
		for (auto i: g[u])
			if (a[i.F] && !mrk[i.F][ck + (a[i.F] == 2)]) 
				if (a[i.F] == 1)
					q.push({w + i.S, i.F + ck * n});
				else if (ck + 1 <= k)
					q.push({(w + i.S) / 2.0, i.F + (ck + 1) * n});
	}
}

double solve(int ns, int ms, int ks, int hs, vector<int> xs, vector<int> ys, vector<int> ws, vector<int> as) {
	n = ns, m = ms, k = min(ks, 75), h = hs;
	for (int i = 0; i < m; i++)
		g[xs[i]].pb({ys[i], ws[i]}), g[ys[i]].pb({xs[i], ws[i]});
	for (int i = 0; i < n; i++)
		a[i] = as[i];
	find_ans();
	for (int i = 0; i < n; i++) {
		g[i].clear();
		t[i] = false;
		for (int j = 0; j <= k; ++j)
			mrk[i][j] = false;
	}
	return ans;
}

Compilation message

cyberland.cpp: In function 'void find_ans()':
cyberland.cpp:59:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   59 |    if (a[i.F] && !mrk[i.F][ck + (a[i.F] == 2)])
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 17 ms 4444 KB Correct.
2 Correct 17 ms 4704 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4444 KB Correct.
2 Correct 21 ms 4624 KB Correct.
3 Correct 20 ms 4444 KB Correct.
4 Correct 21 ms 4700 KB Correct.
5 Correct 23 ms 4444 KB Correct.
6 Correct 21 ms 5720 KB Correct.
7 Correct 28 ms 5720 KB Correct.
8 Correct 13 ms 7260 KB Correct.
9 Correct 20 ms 4460 KB Correct.
10 Correct 24 ms 4444 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 22 ms 4444 KB Correct.
2 Correct 23 ms 4624 KB Correct.
3 Correct 21 ms 4444 KB Correct.
4 Correct 22 ms 4440 KB Correct.
5 Correct 25 ms 4444 KB Correct.
6 Correct 6 ms 5720 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 64 ms 14496 KB Correct.
2 Incorrect 63 ms 6488 KB Wrong Answer.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4700 KB Correct.
2 Correct 21 ms 6492 KB Correct.
3 Correct 21 ms 6700 KB Correct.
4 Correct 23 ms 7612 KB Correct.
5 Correct 21 ms 4700 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6480 KB Correct.
2 Correct 18 ms 4700 KB Correct.
3 Correct 34 ms 15632 KB Correct.
4 Correct 15 ms 7256 KB Correct.
5 Correct 20 ms 4444 KB Correct.
6 Correct 20 ms 6752 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 7024 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 199 ms 7480 KB Wrong Answer.
2 Halted 0 ms 0 KB -