alexjercan/bugnet huggingface dataset:
Problem p01974 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  long n, a[10000];

  cin >> n;

  for (long i = 0; i < n; i++) {
    cin >> a[i];
  }

  int p = 0;

  sort(a, a + n);

  for (long i = 0; i < n; i++) {
    for (long j = 0; j < n; j++) {
      if (i < j && (a[j] - a[i]) % (n - 1) == 0) {
        cout << a[i] << " " << a[j] << endl;
        p += 1;
        break;
      }
    }
    if (p != 0) {
      break;
    }
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  int n, a[100];

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int p = 0;

  sort(a, a + n);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i < j && (a[j] - a[i]) % (n - 1) == 0) {
        cout << a[i] << " " << a[j] << endl;
        p += 1;
        break;
      }
    }
    if (p != 0) {
      break;
    }
  }
}
Problem p01974 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int n;
  cin >> n;
  vector<Int> a(n);
  for (Int i = 0; i < n; i++)
    cin >> a[i];
  for (Int i = 0; i < n; i++) {
    for (Int j = 0; j < i; j++) {
      if (abs(a[i] - a[j]) % (n - 1) == 0) {
        cout << a[i] << " " << a[j] << endl;
        return 0;
      }
    }
  }
  return 0;
}


Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int n;
  cin >> n;
  vector<Int> a(n), b(n);
  for (Int i = 0; i < n; i++)
    cin >> a[i];
  for (Int i = 0; i < n; i++)
    cin >> b[i];

  vector<Int> r(n + 1);
  for (Int i = 0; i < n; i++)
    r[a[i]] = i;

  set<Int> s;
  for (Int i = 0; i < n; i++)
    s.emplace(b[i]);
  if ((Int)s.size() == n) {
    cout << "Yes" << endl;
    return 0;
  }

  Int p = 1;
  while (s.count(p))
    p++;

  cout << "No" << endl;

  for (Int i = 0; i < n; i++) {
    if (i)
      cout << " ";
    if (i == r[p])
      cout << 1;
    else
      cout << i + 1;
  }
  cout << endl;

  for (Int i = 0; i < n; i++) {
    if (i)
      cout << " ";
    if (i == r[p])
      cout << 2;
    else
      cout << i + 1;
  }
  cout << endl;

  return 0;
}
Problem p01975 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  vector<int> ansa(n + 1);
  vector<int> b(n + 1, 0);
  vector<int> ansb(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> ansa[i];
    a[ansa[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> ansb[i];
    b[ansb[i]]++;
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    if (b[i] == 0) {
      ans = i;
      break;
    }
  }
  // cout<<ans<<endl;
  if (ans == -1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
    for (int i = 0; i < n; i++) {
      cout << ansb[i];
      if (i != n - 1)
        cout << " ";
    }
    cout << endl;
    for (int i = 0; i < n; i++) {
      if (ansa[i] == ans) {
        if (ansb[i] == n) {
          cout << ansb[i] - 1;
        } else {
          cout << ansb[i] + 1;
        }
      } else {
        cout << ansb[i];
      }
      if (i != n - 1)
        cout << " ";
    }
    cout << endl;
  }
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  vector<int> ansa(n, 0);
  vector<int> b(n, 0);
  vector<int> ansb(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> ansa[i];
    a[ansa[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> ansb[i];
    b[ansb[i]]++;
  }
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] != 0 && b[i] == 0) {
      ans = a[i];
    }
  }
  // cout<<ans<<endl;
  if (ans == -1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
    for (int i = 0; i < n; i++) {
      cout << ansb[i];
      if (i != n - 1)
        cout << " ";
    }
    cout << endl;
    for (int i = 0; i < n; i++) {
      if (ansa[i] == ans + 1) {
        cout << ansb[i] + 1;
      } else {
        cout << ansb[i];
      }
      if (i != n - 1)
        cout << " ";
    }
    cout << endl;
  }
}
Problem p01975 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[101010];
ll b[101010];
set<ll> st;
bool used[101010];

int main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    cin >> b[i];
    st.insert(b[i]);
  }
  if (st.size() == n) {
    cout << "Yes" << endl;
    return 0;
  }
  for (ll h : st) {
    used[h] = true;
  }
  vector<P> res;
  repl(i, 1, n + 1) {
    if (!used[i]) {
      res.push_back(P(1, 2));
    } else {
      res.push_back(P(1, 1));
    }
  }
  cout << "No" << endl;
  cout << res[a[0] - 1].fi;
  repl(i, 1, n) { cout << " " << res[a[i] - 1].fi; }
  cout << endl;
  cout << res[a[0] - 1].se;
  repl(i, 1, n) { cout << " " << res[a[i] - 1].se; }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[101010];
ll b[101010];
set<ll> st;
bool used[101010];

int main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    cin >> b[i];
    st.insert(b[i]);
  }
  if (st.size() == n) {
    cout << "Yes" << endl;
    return 0;
  }
  for (ll h : st) {
    used[h] = true;
  }
  vector<P> res;
  repl(i, 1, n + 1) {
    if (!used[i]) {
      res.push_back(P(1, 2));
    } else {
      res.push_back(P(1, 1));
    }
  }
  cout << "No" << endl;
  rep(i, n) { cout << res[a[i] - 1].fi << " "; }
  cout << endl;
  rep(i, n) { cout << res[a[i] - 1].se << " "; }
  cout << endl;
  return 0;
}
Problem p01975 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <sys/time.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

void solve(int N, vector<int> a, vector<int> b) {
  vector<int> used(N + 1, 0);
  for (int i = 0; i < N; i++) {
    used[b[i]] = 1;
  }
  int target = -1;
  for (int i = 1; i < N + 1; i++) {
    if (used[i] == 0) {
      target = i;
    }
  }
  if (target == -1) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
    for (int i = 0; i < N - 1; i++) {
      std::cout << 1 << ' ';
    }
    std::cout << 1 << std::endl;
    for (int i = 0; i < N; i++) {
      if (i > 0) {
        std::cout << ' ';
      }
      if (a[i] == target) {
        std::cout << 2;
      } else {
        std::cout << 1;
      }
    }
    std::cout << std::endl;
  }
}

int main() {
  int N;

  std::cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    std::cin >> b[i];
  }
  solve(N, a, b);

  return 0;
}


Error: 0
--Total Time: 0ms


Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <sys/time.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

void solve(int N, vector<int> a, vector<int> b) {
  vector<int> used(N + 1, 0);
  for (int i = 0; i < N; i++) {
    used[b[i]] = 1;
  }
  int target = -1;
  for (int i = 1; i < N + 1; i++) {
    if (used[i] == 0) {
      target = i;
    }
  }
  if (target == -1) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
    for (int i = 0; i < N - 1; i++) {
      std::cout << 1 << ' ';
    }
    std::cout << 1 << std::endl;
    for (int i = 0; i < N; i++) {
      if (i > 0) {
        std::cout << ' ';
      }
      if (a[i] == target) {
        std::cout << 2;
      } else {
        std::cout << 1;
      }
    }
    std::cout << std::endl;
  }
}

int main() {
  struct timeval start, end;
  long long span;
  int N;

  gettimeofday(&start, NULL);

  std::cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    std::cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    std::cin >> b[i];
  }
  solve(N, a, b);

  gettimeofday(&end, NULL);
  span =
      (end.tv_sec - start.tv_sec) * 1000000LL + (end.tv_usec - start.tv_usec);
  std::cerr << "--Total Time: " << span / 1000 << "ms" << endl;
  return 0;
}
Problem p01976 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

// #define int long long
//  typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> v(N);
  rep(i, 0, N) { cin >> v[i]; }
  map<int, int> p, q;
  vector<int> ans;
  rep(i, 0, N) {
    p[v[i]]++, q[v[N - 1 - i]]++;
    if (p == q)
      ans.push_back(i + 1);
  }
  rep(i, 0, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? '\\n' : ' ');

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

// #define int long long
//  typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

bool check(vector<int> a, int m) {
  vector<int> x(a.begin(), a.begin() + m);
  vector<int> y(a.end() - m, a.end());
  sort(all(x));
  sort(all(y));
  return x == y;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  int k = 0;
  vector<int> ans;

  while (k < N) {
    int l = k, r = N - 1 - k, u, t;
    for (u = 0; a[l] != a[r - u]; u++)
      ;
    for (t = 0; a[l + t] != a[r]; t++)
      ;
    dump(k, u, t);
    int m = max(u, t) + 1;
    k += m;
    if (check(a, k)) {
      ans.push_back(k);
    }
  }
  rep(i, 0, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? '\\n' : ' ');

  return 0;
}
Problem p01976 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int W, H;
bool inrange(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define MP make_pair
signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  vector<int> ans;
  map<int, int> s;
  map<int, int> t;
  string a, b;
  rep(i, n) {
    s[v[i]]++;
    t[v[n - i - 1]]++;
    if (s == t)
      ans.push_back(i);
  }
  if (ans.size()) {
    rep(i, ans.size()) {
      if (i) {
        cout << " ";
      }
      cout << ans[i] + 1;
    }
  } else {
    cout << 0;
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int W, H;
bool inrange(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define MP make_pair
signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  vector<int> ans;
  string a, b;
  rep(i, n) {
    a += to_string(v[i]);
    b += to_string(v[v.size() - i - 1]);
    sort(all(a));
    sort(all(b));
    if (a == b)
      ans.push_back(i);
  }
  if (ans.size()) {
    rep(i, ans.size()) {
      if (i) {
        cout << " ";
      }
      cout << ans[i] + 1;
    }
  } else {
    cout << 0;
  }
  cout << endl;
}
Problem p01977 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 N, M;
  cin >> N >> M;
  vector<double> a(N);
  vector<double> sum(N + 1, 0);
  REP(i, N)
  cin >> a[i];
  REP(i, N) { sum[i + 1] = sum[i] + a[i]; }
  vector<vector<vector<long double>>> dp(
      2, vector<vector<long double>>(510, vector<long double>(510, -INF_LL)));
  dp[0][0][0] = 0;
  REP(i, N) {
    dp[1] = vector<vector<long double>>(510, vector<long double>(510, -INF_LL));
    REP(j, M + 1) {
      REP(k, i + 1) {
        chmax(dp[1][j][k], dp[0][j][k]);
        chmax(dp[1][j + 1][i + 1],
              dp[0][j][k] + (sum[i + 1] - sum[k]) / (i - k + 1));
      }
    }
    swap(dp[0], dp[1]);
  }
  cout << fixed << setprecision(10) << dp[0][M][N] << endl;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

double dp[510][510][510] =
    {}; // 今見てる区画、いくつ取り除いたか、さいごに取り除かなかった区画
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 N, M;
  cin >> N >> M;
  vector<double> a(N);
  vector<double> sum(N + 1, 0);
  REP(i, N)
  cin >> a[i];
  REP(i, N) { sum[i + 1] = sum[i] + a[i]; }
  REP(i, 510) REP(j, 510) REP(k, 510) dp[i][j][k] = -INF;
  dp[0][0][0] = 0;
  REP(i, N) {
    REP(j, M + 1) {
      REP(k, i + 1) {
        chmax(dp[i + 1][j][k], dp[i][j][k]);
        chmax(dp[i + 1][j + 1][i + 1],
              dp[i][j][k] + (sum[i + 1] - sum[k]) / (i - k + 1));
      }
    }
  }
  cout << fixed << setprecision(10) << dp[N][M][N] << endl;
}
Problem p01977 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  double waters_cumulative_sum[N + 1];
  waters_cumulative_sum[0] = 0;
  for (int i = 1; i <= N; i++) {
    double water;
    cin >> water;
    waters_cumulative_sum[i] = waters_cumulative_sum[i - 1] + water;
  }
  double dp[N + 1][N], dp_next[N + 1][N];
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] =
          (i > M) * -1e12 +
          (waters_cumulative_sum[N] - waters_cumulative_sum[j]) / (N - j);
    }
  }
  for (int i = N - 1; i >= 1; i--) {
    for (int j = 1; j <= N; j++) {
      for (int k = 0; k < i; k++) {
        dp_next[j][k] =
            max(dp[j][k], dp[j + 1][i] + (waters_cumulative_sum[i] -
                                          waters_cumulative_sum[k]) /
                                             (i - k));
      }
      for (int k = i; k < N; k++) {
        dp_next[j][k] = -1e12;
      }
    }
    for (int j = 1; j <= N; j++) {
      for (int k = 0; k < N; k++) {
        dp[j][k] = dp_next[j][k];
      }
    }
  }
  cout << fixed << setprecision(10) << dp[1][0] << endl;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int N, M;
vector<double> waters_cumulative_sum;

double dp[502][505][505];

double choose(int now, int now_blocks, int back_bound) {
  if (now == N) {
    return (now_blocks > M) * -1e15 +
           (waters_cumulative_sum[N] - waters_cumulative_sum[back_bound]) /
               (N - back_bound);
  } else if (dp[now][now_blocks][back_bound] != -1) {
    return dp[now][now_blocks][back_bound];
  } else {
    return dp[now][now_blocks][back_bound] =
               max(choose(now + 1, now_blocks, back_bound),
                   choose(now + 1, now_blocks + 1, now) +
                       (waters_cumulative_sum[now] -
                        waters_cumulative_sum[back_bound]) /
                           (now - back_bound));
  }
}

int main() {
  cin >> N >> M;
  waters_cumulative_sum.resize(N + 1);
  waters_cumulative_sum[0] = 0;
  for (int i = 1; i <= N; i++) {
    double water;
    cin >> water;
    waters_cumulative_sum[i] = waters_cumulative_sum[i - 1] + water;
  }
  for (int i = 0; i < 502; i++) {
    for (int j = 0; j <= i + 2; j++) {
      for (int k = 0; k <= i + 2; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
  cout << fixed << setprecision(10) << choose(1, 1, 0) << endl;
}
Problem p01978 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)

struct Edge {
  int src, dst, weight;
  Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};

using Graph = vector<vector<Edge>>;

int dijkstra(const Graph &g, int s, int t) {
  const int INF = 1e18;
  using state = tuple<int, int>;
  priority_queue<state> q;
  vector<int> dist(g.size(), INF);
  dist[s] = 0;
  q.emplace(0, s);
  while (q.size()) {
    int d;
    int v;
    tie(d, v) = q.top();
    q.pop();
    d *= -1;
    if (v == t)
      return d;
    if (dist[v] < d)
      continue;
    for (auto &e : g[v]) {
      if (dist[e.dst] > dist[v] + e.weight) {
        dist[e.dst] = dist[v] + e.weight;
        q.emplace(-dist[e.dst], e.dst);
      }
    }
  }
  abort();
}

void add_edge(Graph &g, int s, int t, int w) {
  g[s].emplace_back(s, t, w);
  g[t].emplace_back(t, s, w);
}

signed main() {
  int n, m;
  while (cin >> n >> m) {
    int s, t;
    cin >> s >> t;
    --s;
    --t;
    Graph g(n);
    rep(i, m) {
      int a, b, c, w;
      cin >> a >> b >> c >> w;
      --a;
      --b;
      --c;
      add_edge(g, a, b, w);
      add_edge(g, b, c, w);
      add_edge(g, c, a, w);
    }
    cout << dijkstra(g, s, t) << endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#define int int64_t
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)

struct Edge {
  int src, dst, weight;
  Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};

using Graph = vector<vector<Edge>>;

int dijkstra(const Graph &g, int s, int t) {
  const int INF = 1e9;
  using state = tuple<int, int>;
  priority_queue<state> q;
  vector<int> dist(g.size(), INF);
  dist[s] = 0;
  q.emplace(0, s);
  while (q.size()) {
    int d;
    int v;
    tie(d, v) = q.top();
    q.pop();
    d *= -1;
    if (v == t)
      return d;
    if (dist[v] < d)
      continue;
    for (auto &e : g[v]) {
      if (dist[e.dst] > dist[v] + e.weight) {
        dist[e.dst] = dist[v] + e.weight;
        q.emplace(-dist[e.dst], e.dst);
      }
    }
  }
  abort();
}

void add_edge(Graph &g, int s, int t, int w) {
  g[s].emplace_back(s, t, w);
  g[t].emplace_back(t, s, w);
}

signed main() {
  int n, m;
  while (cin >> n >> m) {
    int s, t;
    cin >> s >> t;
    --s;
    --t;
    Graph g(n);
    rep(i, m) {
      int a, b, c, w;
      cin >> a >> b >> c >> w;
      --a;
      --b;
      --c;
      add_edge(g, a, b, w);
      add_edge(g, b, c, w);
      add_edge(g, c, a, w);
    }
    cout << dijkstra(g, s, t) << endl;
  }
}