제출 #1154823

#제출 시각아이디문제언어결과실행 시간메모리
1154823tapilyocaCyberland (APIO23_cyberland)C++20
68 / 100
439 ms99688 KiB
#include "cyberland.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using ld = long double; class comp{ public: bool operator()(pair<pair<ll,ll>,ll> a, pair<pair<ll,ll>,ll> b){ return a.first.first > b.first.first; } }; ld bleh(ld weight, ll pow){ return weight/(1 << pow); } 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) { vector<vector<pair<ll,ll>>> adj(N+1); // neigjbor, weight for(int i = 0; i < M; i++){ ll a = x[i]; ll b = y[i]; ll w = c[i]; adj[a].push_back({b,w}); adj[b].push_back({a,w}); } bool flag = 0; vector<bool> vis(N+1,0); vis[0] = 1; queue<ll> BFS_q; BFS_q.push(0); while(!BFS_q.empty()){ ll at = BFS_q.front(); BFS_q.pop(); for(pair<ll,ll> p : adj[at]){ ll node = p.first; if(vis[node]) continue; if(node == H){ flag = 1; continue; } vis[node] = 1; BFS_q.push(node); } } if(not flag){ return -1; } // dp-esque? // note that if K too big (over 30??) then we are within range lol K = min(60,K); vector<vector<ld>> dists(N+1, vector<ld>(K+1,-1)); dists[H][0] = 0; // djk // store: dist, k, node priority_queue<pair<pair<ld,ll>,ll>, vector<pair<pair<ld,ll>,ll>>, comp> pq; pq.push({{ld(0),0},H}); while(!pq.empty()){ pair<pair<ld,ll>,ll> front = pq.top(); pq.pop(); ll node = front.second; ld curDist = front.first.first; ll k = front.first.second; if((node == 0 or arr[node] == 0) and vis[node] and node != H){ return curDist; } // cerr << "ON " << node << endl; for(pair<ll,ll> p : adj[node]){ ll neighbor = p.first; if(!vis[neighbor]) continue; ld weight = ld(p.second); // very confusing since we're working backwards // since divide by two divides everything that we've traversed so far (from 0), // dividng by two will divide evertything that we WILL traverse from cyberland // so weight = bleh(weight,k); ld newDist = curDist + weight; if(newDist < dists[neighbor][k] or dists[neighbor][k] == -1){ dists[neighbor][k] = newDist; pq.push({{newDist,k},neighbor}); } if(arr[node] == 2 and node != H and k < K){ // then we can also divide by two here newDist = curDist + weight/ld(2); if(newDist < dists[neighbor][k+1] or dists[neighbor][k+1] == -1){ dists[neighbor][k+1] = newDist; pq.push({{newDist,k+1},neighbor}); } } } } ld mn = 0; for(int i = 0; i < N; i++){ if(i == H) continue; if(!vis[i]) continue; if(arr[i] != 0 and i != 0) continue; for(int j = 0; j <= K; j++){ if(dists[i][j] == -1) continue; if(!mn) mn = dists[i][j]; else mn = min(mn, dists[i][j]); } } return mn; // assert(false); // should never run? }
#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...