Submission #884537

#TimeUsernameProblemLanguageResultExecution timeMemory
884537Trisanu_DasCyberland (APIO23_cyberland)C++17
0 / 100
1494 ms387368 KiB
#include <bits/stdc++.h> #include "cyberland.h" using namespace std; #define ld long double ld dist[2][100005][100]; vector<pair<int, int> > adj[100005]; ld pw[100]; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ for(int i = 0; i < M; i++){ adj[x[i]].push_back({y[i], c[i]}); adj[y[i]].push_back({x[i], c[i]}); } K = min(K, 99); for(int i = 0; i < N; i++) for(int j = 0; j <= K; j++) dist[0][i][j] = dist[1][i][j] = LDBL_MAX; for(int l = K; l > -1; l--){ priority_queue<pair<ld, int> > pq; for(int i = 0; i < N; i++){ if(i == 0){ dist[0][i][l] = 0; pq.push({0, i}); } if(dist[1][i][l] < 1e17) pq.push({-dist[1][i][l], i + 100005}); } while(!pq.empty()){ auto curr = pq.top(); pq.pop(); curr.first *= -1; bool used = curr.second / 100005; if(curr.second == H) continue; if(curr.first > dist[used][curr.second][l]) continue; for(const auto &it : adj[curr.second]){ ld new_c = curr.first + it.second; if(dist[0][it.first][l] > new_c){ dist[0][it.first][l] = new_c; pq.push({-new_c, it.first}); } } } for(int i = 0; i < N; i++){ if(l == 0) continue; if(arr[i] == 2) dist[1][i][l - 1] = dist[0][i][l] / 2.0; else if(arr[i] == 0 && dist[0][i][l] < 1e17) dist[1][i][l] = 0; } } ld ans = min(dist[0][H][0], dist[1][H][0]); if(ans > 1e17) return -1; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...