#include "cyberland.h"
#include <bits/stdc++.h>
const int MAX_N = 1e5 + 10;
const int MAX_K = 100;
typedef long double ld;
ld dist[2][MAX_N][MAX_K];
std::vector<std::pair<int, int> > g[MAX_N];
ld pw[MAX_K];
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].resize(0);
}
for(int i = 0; i < M; i ++) {
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
K = std::min(K, MAX_K - 1);
for(int i = 0; i < N; i ++) {
for(int j = 0; j <= K; j ++) {
dist[0][i][j] = dist[1][i][j] = 1e18;
}
}
for(int left = K; left >= 0; left --) {
std::priority_queue<std::pair<ld, int> > pq;
for(int i = 0; i < N; i ++) {
if(i == 0) {
dist[0][i][left] = 0;
pq.push({0, i});
}
if(dist[1][i][left] < 1e17) {
pq.push({-dist[1][i][left], i + MAX_N});
}
}
while(!pq.empty()) {
auto curr = pq.top(); pq.pop();
curr.first *= -1;
bool used = curr.second / MAX_N;
curr.second %= MAX_N;
if(curr.second == H) { continue; }
if(curr.first > dist[used][curr.second][left]) {
continue;
}
for(const auto &it : g[curr.second]) {
ld new_cost = curr.first + it.second;
if(dist[0][it.first][left] > new_cost) {
dist[0][it.first][left] = new_cost;
pq.push({-new_cost, it.first});
}
}
}
for(int i = 0; i < N; i ++) {
if(left == 0) { continue; }
if(arr[i] == 2) {
dist[1][i][left - 1] = dist[0][i][left] / 2.0;
} else if(arr[i] == 0) {
if(dist[0][i][left] < 1e17) {
dist[1][i][left - 1] = 0;
}
}
}
}
ld ret = std::min(dist[0][H][0], dist[1][H][0]);
if(ret > 1e17) {
return -1;
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
2840 KB |
Correct. |
2 |
Correct |
46 ms |
2796 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
5832 KB |
Correct. |
2 |
Correct |
204 ms |
5864 KB |
Correct. |
3 |
Correct |
193 ms |
6004 KB |
Correct. |
4 |
Correct |
203 ms |
5864 KB |
Correct. |
5 |
Correct |
210 ms |
5860 KB |
Correct. |
6 |
Correct |
283 ms |
34024 KB |
Correct. |
7 |
Correct |
372 ms |
33500 KB |
Correct. |
8 |
Correct |
196 ms |
65500 KB |
Correct. |
9 |
Correct |
118 ms |
3024 KB |
Correct. |
10 |
Correct |
117 ms |
3052 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
423 ms |
5944 KB |
Correct. |
2 |
Correct |
419 ms |
5952 KB |
Correct. |
3 |
Correct |
383 ms |
6092 KB |
Correct. |
4 |
Correct |
210 ms |
3020 KB |
Correct. |
5 |
Correct |
209 ms |
3032 KB |
Correct. |
6 |
Correct |
128 ms |
29032 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
189616 KB |
Correct. |
2 |
Correct |
255 ms |
5972 KB |
Correct. |
3 |
Correct |
227 ms |
6008 KB |
Correct. |
4 |
Correct |
240 ms |
5896 KB |
Correct. |
5 |
Correct |
143 ms |
3020 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
5944 KB |
Correct. |
2 |
Correct |
117 ms |
5984 KB |
Correct. |
3 |
Correct |
124 ms |
5964 KB |
Correct. |
4 |
Correct |
198 ms |
33820 KB |
Correct. |
5 |
Correct |
77 ms |
3024 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
5924 KB |
Correct. |
2 |
Correct |
187 ms |
5908 KB |
Correct. |
3 |
Correct |
163 ms |
244528 KB |
Correct. |
4 |
Correct |
201 ms |
25268 KB |
Correct. |
5 |
Correct |
132 ms |
3028 KB |
Correct. |
6 |
Correct |
219 ms |
5924 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
6024 KB |
Correct. |
2 |
Correct |
41 ms |
8176 KB |
Correct. |
3 |
Incorrect |
861 ms |
306952 KB |
Wrong Answer. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
842 ms |
6032 KB |
Correct. |
2 |
Correct |
115 ms |
8148 KB |
Correct. |
3 |
Correct |
1877 ms |
322044 KB |
Correct. |
4 |
Incorrect |
514 ms |
22828 KB |
Wrong Answer. |
5 |
Halted |
0 ms |
0 KB |
- |