Submission #986702

#TimeUsernameProblemLanguageResultExecution timeMemory
986702CSQ31Cyberland (APIO23_cyberland)C++17
5 / 100
130 ms20060 KiB
#include "cyberland.h" #include<bits/stdc++.h> using namespace std; typedef long double ld; ld dist[64][111111]; ld pw[64]; struct node{ int v,k; ld dist = 0; node(int _v,int _k,ld _dist = 0){ v = _v; k = _k; dist = _dist; } }; struct comp { bool operator() (node const &a, node const &b) { return a.dist - b.dist > 1e-10; } }; vector<pair<int,int>>adj[111111]; double solve(int n, int m,int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){ priority_queue<node,vector<node>,comp>pq; for(int j=0;j<n;j++){ adj[j].clear(); for(int i=0;i<=64;i++){ dist[i][j] = 1e15; } } pw[0] = 1; for(int i=1;i<=64;i++)pw[i] = pw[i-1]*2; 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,64); dist[0][H] = 0; pq.push(node(H,0)); while(!pq.empty()){ node tmp = pq.top(); int v = tmp.v; int k = tmp.k; //cout<<v<<" "<<k<<" "<<tmp.dist<<" "<<dist[k][v]<<'\n'; pq.pop(); if(abs(tmp.dist - dist[k][v]) > 1e-10)continue; if(arr[v] == 0)continue; for(pair<int,int>x : adj[v]){ int u = x.first; if(u == H)continue; ld w = x.second/pw[k]; if(dist[k][u] - dist[k][v] - w > 1e-10){ dist[k][u] = dist[k][v] + w; pq.push(node(u,k,dist[k][u])); } if(arr[u] == 2 && k+1 <= K){ if(dist[k+1][u] - dist[k][v] - w > 1e-10){ dist[k+1][u] = dist[k][v] + w; pq.push(node(u,k+1,dist[k+1][u])); } } } } ld ans = 1e18; for(int i=0;i<=K;i++)ans = min(ans,dist[i][0]); queue<int>q; vector<int>vis(n,0); q.push(0); vis[0] = 1; while(!q.empty()){ int v = q.front(); q.pop(); if(arr[v] == 0){ for(int i=0;i<=K;i++)ans = min(ans,dist[i][v]); } if(v==H)continue; for(pair<int,int>x:adj[v]){ int u = x.first; if(!vis[u]){ q.push(u); vis[u] = 1; } } } if(!vis[H])return -1; return ans; }

Compilation message (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:28:24: warning: iteration 64 invokes undefined behavior [-Waggressive-loop-optimizations]
   28 |             dist[i][j] = 1e15;
      |             ~~~~~~~~~~~^~~~~~
cyberland.cpp:27:22: note: within this loop
   27 |         for(int i=0;i<=64;i++){
      |                     ~^~~~
cyberland.cpp:32:33: warning: iteration 63 invokes undefined behavior [-Waggressive-loop-optimizations]
   32 |     for(int i=1;i<=64;i++)pw[i] = pw[i-1]*2;
      |                           ~~~~~~^~~~~~~~~~~
cyberland.cpp:32:18: note: within this loop
   32 |     for(int i=1;i<=64;i++)pw[i] = pw[i-1]*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...