제출 #836682

#제출 시각아이디문제언어결과실행 시간메모리
836682SoulKnight사이버랜드 (APIO23_cyberland)C++17
15 / 100
810 ms104832 KiB
#include "cyberland.h" // #include "bits/stdc++.h" #include <vector> #include <iostream> #include <array> #include <queue> #include <numeric> using namespace std; #define ll long long #define ln '\n' const int N = 1e5 + 5; const int LG = 50; const long double INF = 5e18; int par[N]; vector<array<ll, 2>> adj[N]; long double dist[N][LG], p2[LG]; priority_queue<array<long double, 3>, vector<array<long double, 3>>, greater<array<long double, 3>>> pq; int find(int u){return (par[u]==u? u: par[u]=find(par[u]));} double solve(int NN, 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 < NN; i++) adj[i].clear(); iota(par, par+NN, 0); K = min(K, LG); p2[0] = 1.0; for (int i = 1; i < LG; i++) p2[i] = p2[i-1] * 2.0; for (int i = 0; i < M; i++){ adj[x[i]].push_back({c[i], y[i]}); adj[y[i]].push_back({c[i], x[i]}); par[find(x[i])] = find(y[i]); } for (int i = 0; i < NN; i++){ if (arr[i] != 0 || find(i) != find(0)) continue; adj[0].push_back({0, i}); adj[i].push_back({0, 0}); } for (int i = 0; i < NN; i++){ for (int j = 0; j < LG; j++) dist[i][j] = INF; } for (int j = 0; j < LG; j++) dist[H][j] = 0.0; pq.push({0.0, H, 0}); // (w, node, # of /2) while (!pq.empty()){ long double w = pq.top()[0]; int u = pq.top()[1]; int cnt = pq.top()[2]; pq.pop(); // cout << w << ' ' << u << ' ' << cnt << ln; // cout << (w > dist[u][cnt]) << ln; if (w > dist[u][cnt]) continue; // cout << "what" << ln; for (auto& [e, v]: adj[u]){ // cout << v << ' ' << dist[v][cnt] << ln; if (dist[v][cnt] >= INF || w * p2[cnt] + e < dist[v][cnt] * p2[cnt]){ dist[v][cnt] = w + e / p2[cnt]; pq.push({dist[v][cnt], v, min(K, cnt + (arr[v] == 2))}); } } } long double ans = INF; for (int j = 0; j <= K; j++){ ans = min(ans, dist[0][j]); // cout << dist[0][j] << " "; } return ((ans >= INF)? -1: ans); }

컴파일 시 표준 에러 (stderr) 메시지

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:49:19: warning: narrowing conversion of 'H' from 'int' to 'long double' [-Wnarrowing]
   49 |     pq.push({0.0, H, 0}); // (w, node, # of /2)
      |                   ^
cyberland.cpp:65:40: warning: narrowing conversion of 'v' from 'std::tuple_element<1, std::array<long long int, 2> >::type' {aka 'long long int'} to 'long double' [-Wnarrowing]
   65 |                 pq.push({dist[v][cnt], v, min(K, cnt + (arr[v] == 2))});
      |                                        ^
cyberland.cpp:65:46: warning: narrowing conversion of '(int)std::min<int>(K, (cnt + (arr.std::vector<int>::operator[](((std::vector<int>::size_type)v)) == 2)))' from 'int' to 'long double' [-Wnarrowing]
   65 |                 pq.push({dist[v][cnt], v, min(K, cnt + (arr[v] == 2))});
      |                                           ~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...