Submission #917641

#TimeUsernameProblemLanguageResultExecution timeMemory
917641shenfe1Cyberland (APIO23_cyberland)C++17
97 / 100
3051 ms158820 KiB
#include <bits/stdc++.h> #include "cyberland.h" #pragma GCC optimize("Ofast") #pragma GCC tartget("avx2") using namespace std; #define F first #define S second #define pb push_back #define pii pair<int,int> const int MAX=1e5+15; const double inf=1e18; int use[MAX]; vector<pii> g[MAX]; double solve(int n,int m,int k,int h,vector<int> x,vector<int> y,vector<int> c,vector<int> arr){ double dp[n+1][67]; for(int i=1;i<=n;i++){ use[i]=0; g[i].clear(); } for(int i=0;i<m;i++){ x[i]++; y[i]++; g[x[i]].pb({y[i],c[i]}); g[y[i]].pb({x[i],c[i]}); // cout<<x[i]<<" "<<y[i]<<" "<<c[i]<<"\n"; } { queue<int> q; q.push(1); use[1]=1; while(!q.empty()){ int v=q.front(); q.pop(); if(v==h+1)continue; for(auto to:g[v]){ if(!use[to.F]){ q.push(to.F); use[to.F]=1; } } } if(!use[h+1]){ return -1.0; } } k=min(k,66); h++; for(int i=1;i<=n;i++){ for(int j=0;j<=k;j++)dp[i][j]=inf; } priority_queue<pair<double,pii>> q; for(int i=1;i<=n;i++){ if((i==1||arr[i-1]==0)&&use[i]){ dp[i][0]=0; q.push({0,{i,0}}); } } while(!q.empty()){ int v=q.top().S.F,c=q.top().S.S; if(dp[v][c]<-q.top().F||v==h){ q.pop(); continue; } q.pop(); // cout<<v<<" "<<c<<" "<<dp[v][c]<<"\n"; for(auto to:g[v]){ if(dp[v][c]+to.S<dp[to.F][c]){ dp[to.F][c]=dp[v][c]+to.S; q.push({-dp[to.F][c],{to.F,c}}); } if(arr[to.F-1]==2){ if(c+1<=k&&(dp[v][c]+to.S)/2<dp[to.F][c+1]){ dp[to.F][c+1]=(dp[v][c]+to.S)/2; q.push({-dp[to.F][c+1],{to.F,c+1}}); } } } } double ans=inf; for(int i=0;i<=k;i++)ans=min(ans,dp[h][i]); return ans; } // int main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // int t; // cin>>t; // cout.precision(10); // while(t--){ // int n,m,k,h; // cin>>n>>m>>k>>h; // vector<int> arr(n); // for(int i=0;i<n;i++)cin>>arr[i]; // vector<int> x(m),y(m),c(m); // for(int i=0;i<m;i++)cin>>x[i]>>y[i]>>c[i]; // cout<<fixed<<solve(n,m,k,h,x,y,c,arr)<<"\n"; // } // }

Compilation message (stderr)

cyberland.cpp:5: warning: ignoring '#pragma GCC tartget' [-Wunknown-pragmas]
    5 | #pragma GCC tartget("avx2")
      |
#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...