This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<int,double>>> al;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> a) {
al.assign(N,vector<pair<int,double>>());
vector<vector<double>> cost(N,vector<double>(N));
for (int i=0; i<M; i++) {
al[x[i]].push_back({y[i],c[i]});
al[y[i]].push_back({x[i],c[i]});
cost[x[i]][y[i]]=c[i];
cost[y[i]][x[i]]=c[i];
}
vector<vector<double>> dp(N,vector<double>(K+1,1e18));
for (int i=0; i<=K; i++) dp[0][i]=0;
for (int i=1; i<=H; i++) {
for (int j=0; j<=K; j++) {
if (a[i]==1||j==0) dp[i][j]=dp[i-1][j]+cost[i][i-1];
else if (a[i]==0) dp[i][j]=0;
else {
dp[i][j]=min((dp[i-1][j-1]+cost[i][i-1])/2,dp[i-1][j]+cost[i][i-1]);
}
}
}
double ans=1e18;
for (int i=0; i<=K; i++) {
ans=min(ans,dp[H][i]);
}
if (ans==1e18) return -1;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |