Submission #1088941

# Submission time Handle Problem Language Result Execution time Memory
1088941 2024-09-15T15:03:24 Z Math4Life2020 Cyberland (APIO23_cyberland) C++17
42 / 100
3000 ms 2097152 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
using ld = long double; using vi = vector<int>;

const ld INF = 1e18;

double solve(int N, int M, int K, int H, vi x, vi y, vi c, vi arr) {
	ld tmin[N][K+1];
	bool dfsf[N];
	for (ll i=0;i<N;i++) {
		dfsf[i]=0;
		for (ll k=0;k<=K;k++) {
			tmin[i][k]=INF;
		}
	}
	vector<pii> adj[N]; //vertex,cost
	for (ll i=0;i<M;i++) {
		adj[x[i]].push_back({y[i],c[i]});
		adj[y[i]].push_back({x[i],c[i]});
	}
	stack<int> s;
	s.push(0);
	while (!s.empty()) {
		ll x = s.top(); s.pop();
		if (!dfsf[x]) {
			dfsf[x]=1;
			for (pii p0: adj[x]) {
				s.push(p0.first);
			}
		}
	}
	if (!dfsf[H]) {
		return -1.0;
	}
	priority_queue<pair<ld,pii>> pq; //{time,{position, #k}}
	pq.push({0.0,{0,0}});
	while (!pq.empty()) {
		auto A = pq.top(); pq.pop();
		ld T = A.first; ll x = A.second.first; ll k = A.second.second;
		if (arr[x]==0) {
			T = 0.0; k = 0;
		}
		if (tmin[x][k]<=(T+1e-10)) {
			continue;
		}
		tmin[x][k]=min(tmin[x][k],T);
		if (x==H) {
			continue;
		}
		for (pii p0: adj[x]) {
			ll y = p0.first; ld ce = p0.second;
			pq.push({ce+T,{y,k}});
			if (arr[x]==2 && k<K) {
				pq.push({ce+T/2,{y,k+1}});
			}
		}
	}
	ld ans = INF;
	for (ll k=0;k<=K;k++) {
		ans = min(ans,tmin[H][k]);
	}
	if (ans == INF) {
		return -1.0;
	} else {
		return ans;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 852 KB Correct.
2 Correct 24 ms 872 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1948 KB Correct.
2 Correct 35 ms 1872 KB Correct.
3 Correct 32 ms 1880 KB Correct.
4 Correct 34 ms 2032 KB Correct.
5 Correct 41 ms 1884 KB Correct.
6 Correct 30 ms 6996 KB Correct.
7 Correct 40 ms 7256 KB Correct.
8 Correct 22 ms 12376 KB Correct.
9 Correct 30 ms 1360 KB Correct.
10 Correct 29 ms 1424 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1884 KB Correct.
2 Correct 45 ms 1816 KB Correct.
3 Correct 42 ms 2016 KB Correct.
4 Correct 36 ms 1360 KB Correct.
5 Correct 36 ms 1368 KB Correct.
6 Correct 11 ms 5212 KB Correct.
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 40296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1192 ms 1872 KB Correct.
2 Correct 1852 ms 2184 KB Correct.
3 Correct 1986 ms 2296 KB Correct.
4 Execution timed out 3075 ms 4564 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 185 ms 2124 KB Correct.
2 Correct 219 ms 1896 KB Correct.
3 Correct 66 ms 47188 KB Correct.
4 Correct 739 ms 5560 KB Correct.
5 Correct 51 ms 1364 KB Correct.
6 Correct 187 ms 2164 KB Correct.
# Verdict Execution time Memory Grader output
1 Execution timed out 3068 ms 66544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1188 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -