이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2,avx,sse3,sse4")
#define F first
#define S second
typedef long long ll;
#define pii pair<int, double>
using namespace std;
const ll mxN = 100000;
const double inf = 1e18;
struct path
{
int i, k;
double val;
};
bool operator<(const path &a, const path &b)
{
return a.val < b.val;
}
bool operator>(const path &a, const path &b)
{
return a.val > b.val;
}
double dp[mxN][71];
vector<pii> v[mxN];
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr)
{
for (int i = 0; i < N; i++)
v[i].clear();
K = min(K,70);
for (int i = 0; i < M; i++)
{
v[x[i]].push_back({y[i], (double)c[i]});
v[y[i]].push_back({x[i], (double)c[i]});
}
for(int i = 0;i < N;i++)
for(int j = 0;j <= K;j++)
dp[i][j] = inf;
priority_queue<path,vector<path>,greater<path>>q;
q.push({0,0,0});
dp[0][0] = 0;
while(q.size()){
const auto u = q.top();
q.pop();
if(u.val < dp[u.i][u.k] || u.i == H) continue;
for(const auto &x : v[u.i]){
if (arr[x.F] == 0 && dp[x.F][u.k] != (double)0)
{
dp[x.F][u.k] = (double)0;
q.push({x.F, u.k, (double)0});
}
if(dp[x.F][u.k] > dp[u.i][u.k] + x.S){
dp[x.F][u.k] = dp[u.i][u.k] + x.S;
q.push({x.F,u.k,dp[x.F][u.k]});
}
if(arr[u.i] == 2 && u.k != K && dp[x.F][u.k + 1] > dp[u.i][u.k] / 2 + x.S){
dp[x.F][u.k + 1] = dp[u.i][u.k] / 2 + x.S;
q.push({x.F,u.k + 1,dp[x.F][u.k + 1]});
}
}
}
double ans = inf;
for(int i = 0;i <= K;i++){
ans = min(ans,dp[H][i]);
}
return ans == inf ? -1 : 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... |