Problem p01415 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

struct UnionFind {
  vector<int> v;
  UnionFind(int n) : v(n) {
    for (int i = 0; i < n; i++)
      v[i] = i;
  }
  int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
  void unite(int x, int y) { v[find(x)] = find(y); }
};
struct state {
  int idx;
  double time;
  int have;
  double limit;
  bool operator<(const state &right) const {
    return time != right.time ? time > right.time
           : idx != right.idx ? idx < right.idx
                              : have < right.have;
  }
};

int main() {
  int n, m;
  double effect, u, v, len;
  cin >> n >> m >> effect >> u >> v >> len;
  vector<double> boost(n);
  REP(i, n)
  cin >> boost[i];
  priority_queue<state> Q;
  Q.push({0, boost[0] / u, 0, 0.0});
  vector<vector<double>> G(n, vector<double>(m + 1, 1e9));
  double ans = 0.0;
  while (!Q.empty()) {
    state q = Q.top();
    Q.pop();
    q.have = min(q.have + 1, m + 1);
    if (q.have == m + 1)
      q.limit = 0;
    if (q.idx == n - 1) {
      if (len - boost[n - 1] - (q.have * effect + q.limit) * v <= 0.0)
        Q.push({n, q.time + (len - boost[n - 1]) / v, 0, 0.0});
      else

        Q.push({n,
                q.time + q.have * effect + q.limit +
                    (len - boost[n - 1] - (q.have * effect + q.limit) * v) / u,
                0, 0.0});
      continue;
    }
    if (q.idx == n) {
      ans = q.time;
      break;
    }
    REP(i, q.have + 1) { //???????????°
      if (q.have - i > m)
        continue;
      double kasoku_load = (q.limit + effect * i) * v;
      if (boost[q.idx + 1] - boost[q.idx] <= kasoku_load) {
        if (G[q.idx + 1][q.have - i] >
            q.time + (boost[q.idx + 1] - boost[q.idx]) / v) {
          Q.push({q.idx + 1, q.time + (boost[q.idx + 1] - boost[q.idx]) / v,
                  q.have - i,
                  max(0.0, q.limit + effect * i -
                               (boost[q.idx + 1] - boost[q.idx]) / v)});
          G[q.idx + 1][q.have - i] =
              q.time + (boost[q.idx + 1] - boost[q.idx]) / v;
        }
        break;
      } else {
        if (G[q.idx + 1][q.have - i] >
            q.time + q.limit + effect * i +
                (boost[q.idx + 1] - boost[q.idx] - kasoku_load) / u) {
          Q.push({q.idx + 1,
                  q.time + q.limit + effect * i +
                      (boost[q.idx + 1] - boost[q.idx] - kasoku_load) / u,
                  q.have - i, 0.0});
          G[q.idx + 1][q.have - i] =
              q.time + q.limit + effect * i +
              (boost[q.idx + 1] - boost[q.idx] - kasoku_load) / u;
        }
      }
    }
  }

  printf("%.9lf\\n", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

struct UnionFind {
  vector<int> v;
  UnionFind(int n) : v(n) {
    for (int i = 0; i < n; i++)
      v[i] = i;
  }
  int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
  void unite(int x, int y) { v[find(x)] = find(y); }
};
struct state {
  int idx;
  double time;
  int have;
  double limit;
  bool operator<(const state &right) const {
    return time != right.time ? time > right.time
           : idx != right.idx ? idx > right.idx
                              : have < right.have;
  }
};

int main() {
  int n, m;
  double effect, u, v, len;
  cin >> n >> m >> effect >> u >> v >> len;
  vector<double> boost(n);
  REP(i, n)
  cin >> boost[i];
  priority_queue<state> Q;
  Q.push({0, boost[0] / u, 0, 0.0});
  double ans = 0.0;
  while (!Q.empty()) {
    state q = Q.top();
    Q.pop();
    q.have = min(q.have + 1, m + 1);
    if (q.idx == n - 1) {
      if (q.have == m + 1)
        q.limit = 0;
      if (len - boost[n - 1] - (q.have * effect + q.limit) * v <= 0.0)
        Q.push({n, q.time + (len - boost[n - 1]) / v, 0, 0.0});
      else

        Q.push({n,
                q.time + q.have * effect + q.limit +
                    (len - boost[n - 1] - (q.have * effect + q.limit) * v) / u,
                0, 0.0});
      continue;
    }
    if (q.idx == n) {
      ans = q.time;
      break;
    }
    REP(i, q.have + 1) { //???????????°
      if (q.have - i > m)
        continue;
      double kasoku_load = (q.limit + effect * i) * v;
      if (boost[q.idx + 1] - boost[q.idx] <= kasoku_load) {
        Q.push({q.idx + 1, q.time + (boost[q.idx + 1] - boost[q.idx]) / v,
                q.have - i,
                max(0.0, q.limit + effect * i -
                             (boost[q.idx + 1] - boost[q.idx]) / v)});
        break;
      } else {
        Q.push({q.idx + 1,
                q.time + q.limit + effect * i +
                    (boost[q.idx + 1] - boost[q.idx] - kasoku_load) / u,
                q.have - i, 0.0});
      }
    }
  }

  printf("%.9lf\\n", ans);
}