Submission #1355815

#TimeUsernameProblemLanguageResultExecution timeMemory
1355815kawhietCyberland (APIO23_cyberland)C++20
0 / 100
14 ms6704 KiB
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;

constexpr double inf = 1e18;

vector<vector<pair<int, int>>> g;

vector<double> get(int t, int n, int skip) {
  priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
  vector<double> d(n, inf);
  d[t] = 0;
  pq.push({0, t});
  while (!pq.empty()) {
    auto [k, u] = pq.top();
    pq.pop();
    if (k > d[u]) continue;
    for (auto [v, w] : g[u]) {
      if (v == skip) continue;
      if (d[v] > k + w) {
        d[v] = k + w;
        pq.push({d[v], v});
      }
    }
  }
  return d;
}

double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
  g.assign(n, {});
  for (int i = 0; i < m; i++) {
    g[x[i]].push_back({y[i], c[i]});
    g[y[i]].push_back({x[i], c[i]});
  }
  vector<double> t = get(0, n, -1);
  vector<double> d = get(h, n, 0);
  vector<double> s = get(0, n, h);
  if (t[h] == inf) {
    return -1;
  }
  double mn = t[h];
  int pos = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0 && s[i] != inf) {
      if (d[i] < mn) {
        mn = d[i];
        pos = i;
      }
    }
  }
  double chk = 0;
  for (int i = pos; i < h; i++) {
    chk += c[i];
  }
  assert(chk == mn);
  int left = 0;
  for (int i = pos + 1; i <= h; i++) {
    if (arr[i] == 2) {
      left++;
    }
  }
  double ans = 0;
  for (int i = pos; i < h; i++) {
    ans += c[i];
    if (arr[i + 1] == 2) {
      if (left == 2 && k % 2 == 0) {
        ans /= 2;
        k--;
      }
      if (left == 1) {
        k--;
        for (int j = 0; j + 2 < k; j += 2) {
          ans /= 2;
          ans += c[i];
          ans /= 2;
          ans += c[i];
        }
        ans /= 2;
      }
      left--;
    }
  }
  return ans;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...