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

#include <algorithm>
#include <cstdio>
using namespace std;
#define INF ((1 << 30) - 1)
int n;
struct Tree {
  Tree *c1, *c2;
  int L, S, pv;
  Tree(int b, int e) {
    L = 0;
    c1 = c2 = NULL;
    pv = b - 1;
    S = -1 * (e - b + 1);
  }
  Tree GetMax(int b, int e, int s) {
    if (b == s)
      return *this;
    int m = (b + e) >> 1;
    if (!c1) {
      c1 = new Tree(b, m);
      c2 = new Tree(m + 1, e);
    }
    if (m < s)
      return c2->GetMax(m + 1, e, s);
    Tree ret = c1->GetMax(b, m, s);
    if (ret.L < ret.S + c2->L) {
      ret.L = ret.S + c2->L;
      ret.pv = c2->pv;
    }
    ret.S = ret.S + c2->S;
    return ret;
  }
  void Add(int b, int e, int x) {
    if (b == e) {
      S++;
      if (S > 0) {
        L = S;
        pv = b;
      }
      return;
    }
    int m = (b + e) >> 1;
    if (c1 == NULL) {
      c1 = new Tree(b, m);
      c2 = new Tree(m + 1, e);
    }
    if (x <= m)
      c1->Add(b, m, x);
    else
      c2->Add(m + 1, e, x);
    S = c1->S + c2->S;
    L = max(c1->L, c1->S + c2->L);
    pv = c1->pv;
    if (L != c1->L)
      pv = c2->pv;
  }
  int Sum(int b, int e, int x) {
    if (b == x)
      return S;
    int m = (b + e) >> 1, r = 0;
    if (!c1) {
      c1 = new Tree(b, m);
      c2 = new Tree(m + 1, e);
    }
    if (x <= m) {
      r = c2->S + c1->Sum(b, m, x);
    } else {
      r = c2->Sum(m + 1, e, x);
    }
    return r;
  }
};
int main() {
  int i, a;
  scanf("%d", &n);
  long long res = 0, SS = 0;
  Tree *Root = new Tree(0, INF);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    Tree rr = Root->GetMax(0, INF, a + 1);
    res += rr.pv - a;
    res += Root->Sum(0, INF, rr.pv + 1) + (INF - rr.pv);
    Root->Add(0, INF, rr.pv);
    SS += rr.pv - a;
  }
  printf("%lld\\n", res);
}

Error: 0

Fixed submission:


#include <algorithm>
#include <cstdio>
using namespace std;
int n, w[201000], Loc[201000], G[201000];
struct point {
  int x, num;
  bool operator<(const point &p) const {
    return x != p.x ? x < p.x : num < p.num;
  }
} ord[210000];
void RTE() {
  RTE();
  RTE();
}
int main() {
  int i, j;
  scanf("%d", &n);
  if (n > 10000) {
    RTE();
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
    Loc[i] = i;
    G[i] = i;
    ord[i] = {w[i], i};
  }
  sort(ord + 1, ord + n + 1);
  long long res = 0;
  for (i = 1; i <= n; i++) {
    int t = Loc[ord[i].num];
    int M = 0, Mn = 2e9, xx = 0, U = -1;
    for (j = 1; j <= t; j++) {
      if (Mn >= max(0, M - ord[i].x) + (t - j)) {
        Mn = max(0, M - ord[i].x) + (t - j);
        U = max(M, ord[i].x);
        xx = j;
      }
      M = max(M, w[G[j]]);
    }
    w[ord[i].num] = U;
    res += Mn;
    for (j = t; j > xx; j--) {
      swap(G[j - 1], G[j]);
      swap(Loc[G[j - 1]], Loc[G[j]]);
    }
  }
  printf("%lld\\n", res);
}
Problem p03531 (C++) — buggy submission, verdict: Runtime Error

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

int n, A[1 << 18], l[1 << 18], r[1 << 18];
vector<int> add[1 << 18], del[1 << 18];
struct cmp {
  bool operator()(int p, int q) { return r[p] > r[q]; }
};
priority_queue<int, vector<int>, cmp> q;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 1 << n; ++i) {
    scanf("%d", A + i);
    if (A[i])
      l[i] = r[i] = A[i];
    else
      l[i] = 1, r[i] = 1 << n;
  }
  for (int i = 0; i < 1 << n; ++i)
    for (int j = 0; j < n; ++j)
      if (!(i >> j & 1))
        l[i ^ (1 << j)] = max(l[i ^ (1 << j)], l[i] + 1);
  for (int i = (1 << n) - 1; i >= 0; --i)
    for (int j = 0; j < n; ++j)
      if (i >> j & 1)
        r[i ^ (1 << j)] = min(r[i ^ (1 << j)], r[i] - 1);
  for (int i = 0; i < 1 << n; ++i) {
    if (l[i] > r[i])
      return puts("NO"), 0;
    add[l[i] - 1].push_back(i);
    del[r[i] - 1].push_back(i);
  }
  for (int i = 0; i < 1 << n; ++i) {
    for (int x : add[i])
      q.push(x);
    if (!q.empty())
      A[q.top()] = i + 1, q.pop();
    for (int x : del[i])
      if (!A[x])
        return puts("NO"), 0;
  }
  for (int i = 0, j = 0; i < 1 << n; ++i) {
    if (i > j)
      swap(A[i], A[j]);
    for (int k = 1 << n - 1; (j ^= k) < k; k >>= 1)
      ;
  }
  puts("YES");
  for (int i = 0; i < 1 << n; ++i)
    printf("%d%c", A[i], " \\n "[i + 1 == 1 << n]);
  return 0;
}


Error: WA

Fixed submission:

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

int n, A[1 << 18], l[1 << 18], r[1 << 18];
vector<int> add[1 << 18], del[1 << 18];
struct cmp {
  bool operator()(int p, int q) { return r[p] > r[q]; }
};
priority_queue<int, vector<int>, cmp> q;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 1 << n; ++i) {
    scanf("%d", A + i);
    if (A[i])
      l[i] = r[i] = A[i];
    else
      l[i] = 1, r[i] = 1 << n;
  }
  for (int i = 0; i < 1 << n; ++i)
    for (int j = 0; j < n; ++j)
      if (!(i >> j & 1))
        l[i ^ (1 << j)] = max(l[i ^ (1 << j)], l[i] + 1);
  for (int i = (1 << n) - 1; i >= 0; --i)
    for (int j = 0; j < n; ++j)
      if (i >> j & 1)
        r[i ^ (1 << j)] = min(r[i ^ (1 << j)], r[i] - 1);
  for (int i = 0; i < 1 << n; ++i) {
    if (l[i] > r[i])
      return puts("NO"), 0;
    add[l[i]].push_back(i);
    del[r[i]].push_back(i);
  }
  for (int i = 0; i < 1 << n; ++i) {
    for (int x : add[i])
      q.push(x);
    while (!q.empty() && A[q.top()])
      q.pop();
    if (!q.empty())
      A[q.top()] = i;
    for (int x : del[i])
      if (!A[x])
        return puts("NO"), 0;
  }
  for (int i = 0, j = 0; i < 1 << n; ++i) {
    if (i > j)
      swap(A[i], A[j]);
    for (int k = 1 << n - 1; (j ^= k) < k; k >>= 1)
      ;
  }
  puts("YES");
  for (int i = 0; i < 1 << n; ++i)
    printf("%d%c", A[i], " \\n "[i + 1 == 1 << n]);
  return 0;
}
Problem p03537 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;

string S;
ll N, L[200000], R[200000];
vector<ll> E[200000];
vector<ll> d;
bool visited[200000];

ll dfs(ll v) {
  if (visited[v])
    return 0;
  visited[v] = true;

  ll ret = d[v];
  for (ll u : E[v])
    ret += dfs(u);
  return ret;
}

int main(void) {
  cin >> S >> N;
  REP(i, 0, N) cin >> L[i] >> R[i], L[i]--, R[i];

  S = "a" + S + "a";
  REP(i, 0, S.length() - 1) d.push_back((S[i + 1] - S[i] + 26) % 26);

  REP(i, 0, N) {
    E[L[i]].push_back(R[i]);
    E[R[i]].push_back(L[i]);
  }
  REP(i, 0, (d.size()) / 2) {
    E[i].push_back(d.size() - 1 - i);
    E[d.size() - 1 - i].push_back(i);
  }

  bool ans = true;
  REP(i, 0, d.size()) visited[i] = false;
  REP(i, 0, d.size()) {
    ll sum = dfs(i) % 26;
    if (sum != 0)
      ans = false;
  }
  cout << (ans ? "YES" : "NO") << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;

string S;
ll N, L[100000], R[100000];
vector<ll> E[100000];
vector<ll> d;
bool visited[100000];

ll dfs(ll v) {
  if (visited[v])
    return 0;
  visited[v] = true;

  ll ret = d[v];
  for (ll u : E[v])
    ret += dfs(u);
  return ret;
}

int main(void) {
  cin >> S >> N;
  REP(i, 0, N) cin >> L[i] >> R[i], L[i]--, R[i];

  S = "a" + S + "a";
  REP(i, 0, S.length() - 1) d.push_back((S[i + 1] - S[i] + 26) % 26);

  REP(i, 0, N) {
    E[L[i]].push_back(R[i]);
    E[R[i]].push_back(L[i]);
  }
  REP(i, 0, (d.size()) / 2) {
    E[i].push_back(d.size() - 1 - i);
    E[d.size() - 1 - i].push_back(i);
  }

  bool ans = true;
  REP(i, 0, S.length() - 1) visited[i] = false;
  REP(i, 0, S.length() - 1) {
    ll sum = dfs(i) % 26;
    if (sum != 0)
      ans = false;
  }
  cout << (ans ? "YES" : "NO") << endl;
}
Problem p03537 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define maxn 1000100
using namespace std;
int n, sum[maxn * 2], tp, m, a[maxn], f[maxn];
char s[maxn];
int g(int x) { return x < 0 ? x + 26 : x; }
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
int main() {
  scanf("%s%d", s + 1, &n);
  int m = strlen(s + 1);
  for (int i = 1; i <= m; ++i)
    s[i] -= 'a', f[i] = i;
  f[m + 1] = m + 1;
  for (int i = m + 1; i >= 1; --i)
    s[i] = g(s[i] - s[i - 1]);
  for (int i = 1, l, r; i <= n; ++i)
    scanf("%d%d", &l, &r), f[find(l)] = find(r + 1);
  for (int i = 1; i <= m - i + 2; ++i)
    f[find(i)] = find(m + 2 - i);
  for (int i = 1; i <= m + 1; ++i)
    sum[find(i)] += s[i];
  for (int i = 1; i <= m + 1; ++i)
    if (i == find(i) && sum[i] % 26)
      return puts("NO"), 0;
  puts("YES");
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define maxn 100100
using namespace std;
int n, sum[maxn * 2], tp, m, a[maxn], f[maxn];
char s[maxn];
int g(int x) { return x < 0 ? x + 26 : x; }
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
int main() {
  scanf("%s%d", s + 1, &n);
  int m = strlen(s + 1);
  for (int i = 1; i <= m; ++i)
    s[i] -= 'a', f[i] = i;
  f[m + 1] = m + 1;
  for (int i = m + 1; i >= 1; --i)
    s[i] = g(s[i] - s[i - 1]);
  for (int i = 1, l, r; i <= n; ++i)
    scanf("%d%d", &l, &r), f[find(l)] = find(r + 1);
  for (int i = 1; i <= m - i + 2; ++i)
    f[find(i)] = find(m + 2 - i);
  for (int i = 1; i <= m + 1; ++i)
    sum[find(i)] += s[i];
  for (int i = 1; i <= m + 1; ++i)
    if (i == find(i) && sum[i] % 26)
      return puts("NO");
  puts("YES");
}
Problem p03539 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

ll N, K;

int main(void) {
  cin >> N >> K;

  ll p = 1;
  REP(i, 0, N - 1) p = (p * (K + 1)) % MOD;
  ll all = (p * ((K * (K + 1) / 2) % MOD)) % MOD * N % MOD;

  vector<vector<ll>> dp(N + 1, vector<ll>(3500, 0));
  dp[0][0] = 1;
  REP(i, 0, N) {
    REP(j, 0, K + 1) {
      REP(k, 0, 3500) {
        if (dp[i][k] == 0)
          continue;
        if (j <= N - i) {
          if (k + (k + j) / (N - i) < 3500) {
            dp[i + 1][k + (k + j) / (N - i)] += dp[i][k];
            dp[i + 1][k + (k + j) / (N - i)] %= MOD;
          }
        } else {
          dp[i + 1][k] += dp[i][k];
          dp[i + 1][k] %= MOD;
        }
      }
    }
  }

  ll ans = 0;
  REP(i, 0, 3500) {
    ans += (dp[N][i] * i) % MOD;
    ans %= MOD;
  }
  cout << (all - ans + MOD) % MOD << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

ll N, K;

int main(void) {
  cin >> N >> K;

  ll p = 1;
  REP(i, 0, N - 1) p = (p * (K + 1)) % MOD;
  ll all = (p * ((K * (K + 1) / 2) % MOD)) % MOD * N % MOD;

  vector<vector<ll>> dp(N + 1, vector<ll>(3500, 0));
  dp[0][0] = 1;
  REP(i, 0, N) {
    REP(j, 0, K + 1) {
      REP(k, 0, 3500) {
        if (j <= N - i) {
          dp[i + 1][k + (k + j) / (N - i)] += dp[i][k];
          dp[i + 1][k + (k + j) / (N - i)] %= MOD;
        } else {
          dp[i + 1][k] += dp[i][k];
          dp[i + 1][k] %= MOD;
        }
      }
    }
  }

  ll ans = 0;
  REP(i, 0, 3500) {
    ans += (dp[N][i] * i) % MOD;
    ans %= MOD;
  }
  cout << (all - ans + MOD) % MOD << endl;
}
Problem p03539 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  const long long mod = 1000000007;
  int N, K;
  scanf("%d %d", &N, &K);
  long long pw[101] = {
      1,
  };
  for (int i = 1; i <= N; i++)
    pw[i] = pw[i - 1] * (K + 1) % mod;

  long long ans = N * K * (K + 1) / 2 * pw[N - 1] % mod;
  long long prv[8000] = {
      1,
  };
  for (int i = N; i >= 1; i--) {
    long long nxt[8000] = {
        0,
    };
    for (int k = 0; k <= K; k++) {
      for (int j = 0; j < 8000; j++)
        if (prv[j]) {
          int v = (j + k) / i;
          if (k > i)
            v = 0;
          ans = (ans + mod - pw[i - 1] * v % mod * prv[j] % mod) % mod;
          nxt[j + v] = (nxt[j + v] + prv[j]) % mod;
        }
    }
    for (int j = 0; j < 8000; j++)
      prv[j] = nxt[j];
  }

  printf("%lld\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  const long long mod = 1000000007;
  int N, K;
  scanf("%d %d", &N, &K);
  long long pw[101] = {
      1,
  };
  for (int i = 1; i <= N; i++)
    pw[i] = pw[i - 1] * (K + 1) % mod;

  long long ans = N * K * (K + 1) / 2 * pw[N - 1] % mod;
  long long prv[1000] = {
      1,
  };
  for (int i = N; i >= 1; i--) {
    long long nxt[1000] = {
        0,
    };
    for (int k = 0; k <= K; k++) {
      for (int j = 0; j < 1000; j++)
        if (prv[j]) {
          int v = (j + k) / i;
          if (k > i)
            v = 0;
          ans = (ans + mod - pw[i - 1] * v % mod * prv[j] % mod) % mod;
          nxt[j + v] = (nxt[j + v] + prv[j]) % mod;
        }
    }
    for (int j = 0; j < 1000; j++)
      prv[j] = nxt[j];
  }

  printf("%lld\\n", ans);

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

#include "bits/stdc++.h"
using namespace std;
const int maxn = 103;
const int magic = 4040;
const int mod = 1000000007;
long long o[maxn][maxn * maxn];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  o[n + 1][0] = 1;
  for (int e = n; e >= 1; e--) {
    for (int s = 0; s < magic; s++) {
      if (o[e + 1][s] == 0)
        continue;
      for (int f = 0; f <= k; f++) {
        if (f <= e) {
          o[e][s + (f + s) / e] += o[e + 1][s];
          o[e][s + (f + s) / e] %= mod;
        } else {
          o[e][s] += o[e + 1][s];
          o[e][s] %= mod;
        }
      }
    }
  }
  long long comb = k * (k + 1) / 2;
  comb *= n;
  comb %= mod;
  for (int e = 0; e < n - 1; e++)
    comb *= (k + 1), comb %= mod;
  long long ans = comb;
  for (int e = 0; e < magic; e++)
    ans += mod - (e * o[1][e] % mod), ans %= mod;
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
const int maxn = 101;
const int magic = 4040;
const int mod = 1000000007;
long long o[maxn][maxn * maxn];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  o[n + 1][0] = 1;
  for (int e = n; e >= 1; e--) {
    for (int s = 0; s < magic; s++) {
      if (o[e + 1][s] == 0)
        continue;
      for (int f = 0; f <= k; f++) {
        if (f <= e) {
          o[e][s + (f + s) / e] += o[e + 1][s];
          o[e][s + (f + s) / e] %= mod;
        } else {
          o[e][s] += o[e + 1][s];
          o[e][s] %= mod;
        }
      }
    }
  }
  long long comb = k * (k + 1) / 2;
  comb *= n;
  comb %= mod;
  for (int e = 0; e < n - 1; e++)
    comb *= (k + 1), comb %= mod;
  long long ans = comb;
  for (int e = 0; e < magic; e++)
    ans += mod - (e * o[1][e] % mod), ans %= mod;
  cout << ans << endl;
  return 0;
}
Problem p03541 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
int mini[1 << 18], maxi[1 << 18];
vector<pii> qs[1000000];
int ans[1000000];
int main() {
  int num;
  scanf("%d", &num);
  fill(maxi, maxi + (1 << num), 1 << num);
  fill(mini, mini + (1 << num), 1);
  for (int i = 0; i < (1 << num); i++) {
    int z;
    scanf("%d", &z);
    if (z > 0)
      mini[i] = maxi[i] = z;
  }
  for (int i = 0; i < num; i++) {
    for (int j = 0; j < (1 << num); j++) {
      if (j & (1 << i))
        maxi[j - (1 << i)] = min(maxi[j - (1 << i)], maxi[j]);
      else
        mini[j + (1 << i)] = max(mini[j + (1 << i)], mini[j]);
    }
  }
  // for (int i = 0; i < (1 << num); i++)printf("%d %d\\n", mini[i], maxi[i]);
  for (int i = 0; i < (1 << num); i++)
    qs[maxi[i]].push_back(make_pair(mini[i], i));
  priority_queue<pi3> que;
  for (int i = (1 << num); i >= 1; i--) {
    for (int j = 0; j < qs[i].size(); j++) {
      que.push(make_pair(make_pair(qs[i][j].first, i), qs[i][j].second));
    }
    if (que.empty()) {
      printf("NO\\n");
      return 0;
    }
    pi3 z = que.top();
    que.pop();
    if (!(z.first.first <= i && i <= z.first.second)) {
      printf("NO\\n");
      return 0;
    }
    ans[z.second] = i;
  }
  printf("YES\\n");
  for (int i = 0; i < (1 << num); i++) {
    int p = 0;
    for (int j = 0; j < num; j++)
      if (i & (1 << j))
        p += 1 << (num - 1 - j);
    printf("%d ", ans[p]);
  }
  printf("\\n");
}

Error: WA

Fixed submission:

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
int mini[1 << 18], maxi[1 << 18];
vector<pii> qs[1000000];
int ans[1000000];
int main() {
  int num;
  scanf("%d", &num);
  fill(maxi, maxi + (1 << num), 1000000000);
  for (int i = 0; i < (1 << num); i++) {
    int z;
    scanf("%d", &z);
    if (z > 0)
      mini[i] = maxi[i] = z;
  }
  for (int i = 0; i < num; i++) {
    for (int j = 0; j < (1 << num); j++) {
      if (j & (1 << i))
        maxi[j - (1 << i)] = min(maxi[j - (1 << i)], maxi[j]);
      else
        mini[j + (1 << i)] = max(mini[j + (1 << i)], mini[j]);
    }
  }
  // for (int i = 0; i < (1 << num); i++)printf("%d %d\\n", mini[i], maxi[i]);
  for (int i = 0; i < (1 << num); i++)
    qs[maxi[i]].push_back(make_pair(mini[i], i));
  priority_queue<pi3> que;
  for (int i = (1 << num); i >= 1; i--) {
    for (int j = 0; j < qs[i].size(); j++) {
      que.push(make_pair(make_pair(qs[i][j].first, i), qs[i][j].second));
    }
    if (que.empty()) {
      printf("NO\\n");
      return 0;
    }
    pi3 z = que.top();
    que.pop();
    if (!(z.first.first <= i && i <= z.first.second)) {
      printf("NO\\n");
      return 0;
    }
    ans[z.second] = i;
  }
  printf("YES\\n");
  for (int i = 0; i < (1 << num); i++) {
    int p = 0;
    for (int j = 0; j < num; j++)
      if (i & (1 << j))
        p += 1 << (num - 1 - j);
    printf("%d ", ans[p]);
  }
  printf("\\n");
}
Problem p03755 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)

using namespace std;
const int MAX_X = 2500, MAX_K = 2500;
int K, X, S[MAX_K], N;
const ll MOD = 1e9 + 7;
int dp[MAX_X * 2][10000], psm[MAX_X * 2][10001];
int main() {
  scanf("%d %d %d", &N, &K, &X);
  REP(i, K) { scanf("%d", S + i); }
  dp[0][0] = 1;
  REP(i, 10000 - 1) dp[0][i + 1] = 0;
  psm[0][0] = 0;
  REP(i, 10000) { psm[0][i + 1] = 1; }
  FOR(i, 1, 2 * X) {
    REP(j, 10000) {
      int ub;
      if (i % 2) {
        ub = max(j - i - 1, 0);
      } else {
        ub = max(j - i, 0);
      }
      dp[i][j] =
          (int)((((ll)psm[i - 1][j] - psm[i - 1][ub] + MOD) + (j <= i)) % MOD);
      psm[i][j + 1] = (int)(((ll)psm[i][j] + dp[i][j]) % MOD);
    }
  }
  ll ans = 1;
  REP(i, K - 1) {
    if (X * 2 - 1 - i * 2 >= 0) {
      ans *= dp[X * 2 - 1 - i * 2][S[i + 1] - S[i] - 1];
    } else {
      ans = 0;
    }
    ans %= MOD;
  }
  printf("%lld\\n", ans);
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)

using namespace std;
const int MAX_X = 2500, MAX_K = 2500;
int K, X, S[MAX_K], N;
const ll MOD = 1e9 + 7;
ll dp[MAX_X * 2][10000], psm[MAX_X * 2][10001];
int main() {
  scanf("%d %d %d", &N, &K, &X);
  REP(i, K) { scanf("%d", S + i); }
  dp[0][0] = 1;
  REP(i, 10000 - 1) dp[0][i + 1] = 0;
  psm[0][0] = 0;
  REP(i, 10000) { psm[0][i + 1] = 1; }
  FOR(i, 1, 2 * X) {
    REP(j, 10000) {
      int ub;
      if (i % 2) {
        ub = max(j - i - 1, 0);
      } else {
        ub = max(j - i, 0);
      }
      dp[i][j] = ((psm[i - 1][j] - psm[i - 1][ub] + MOD) + (j <= i)) % MOD;
      psm[i][j + 1] = (psm[i][j] + dp[i][j]) % MOD;
    }
  }
  ll ans = 1;
  REP(i, K - 1) {
    if (X * 2 - 1 - i * 2 >= 0) {
      ans *= dp[X * 2 - 1 - i * 2][S[i + 1] - S[i] - 1];
    } else {
      ans = 0;
    }
    ans %= MOD;
  }
  printf("%lld\\n", ans);
}
Problem p03869 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using P = complex<double>;

namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std

const double EPS{1e-9};
auto m = [](int x) { return x % 3; };

double cross(const P &a, const P &b) { return imag(conj(a) * b); }

double area2(const vector<P> p) {
  P a{p[1] - p[0]};
  P b{p[2] - p[0]};
  return abs(real(a) * imag(b) - imag(a) * real(b));
}

int main() {
  vector<P> p(3);
  for (int i = 0; i < 3; i++) {
    double x, y;
    cin >> x >> y;
    p[i] = {x, y};
  }
  double ls{}, lmx{};
  for (int i = 0; i < 3; i++) {
    double l{abs(p[m(i + 1)] - p[m(i)])};
    ls += l;
    lmx = max(lmx, l);
  }
  double r{area2(p) / ls};
  cout << fixed << setprecision(10) << lmx * r / (lmx + 2.0 * r) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using P = complex<double>;

namespace std {
bool operator<(const P &a, const P &b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std

const double EPS{1e-9};
auto m = [](int x) { return x % 3; };

double cross(const P &a, const P &b) { return imag(conj(a) * b); }

double area2(const vector<P> p) {
  P a{p[1] - p[0]};
  P b{p[2] - p[0]};
  double theta{abs(arg(b) - arg(a))};
  return abs(a) * abs(b) * sin(theta);
}

int main() {
  vector<P> p(3);
  for (int i = 0; i < 3; i++) {
    double x, y;
    cin >> x >> y;
    p[i] = {x, y};
  }
  double ls{}, lmx{};
  for (int i = 0; i < 3; i++) {
    double l{abs(p[m(i + 1)] - p[m(i)])};
    ls += l;
    lmx = max(lmx, l);
  }
  double y{area2(p) / ls};
  auto f = [=](double x) { return (1.0 - x / y) * lmx - 2.0 * x; };
  double x{}, l{}, r{y};
  while (abs(f(x)) > EPS) {
    x = (l + r) / 2.0;
    ((f(x) >= 0) ? l : r) = x;
  }
  cout << fixed << setprecision(9) << x << endl;
  return 0;
}
Problem p03872 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 17;
double dis[N][N], f[1 << N], x[N], y[N], a[N];
int n, m;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      dis[i][j] =
          sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
  for (int i = 0; i <= 1 << n; i++)
    f[i] = 1e18;
  f[0] = 0;
  for (int i = 0; i < n; i++)
    f[1 << i] = 0;
  for (int s = 0; s < 1 << n; s++) {
    for (int i = 0; i <= n - 1; i++)
      for (int j = 0; j <= n - 1; j++)
        if ((s & (1 << i)) && (!(s & (1 << j))))
          f[s | (1 << j)] = min(f[s | (1 << j)], f[s] + dis[i + 1][j + 1]);
  }
  for (int s = 0; s < 1 << n; s++) {
    f[s] = -f[s];
    for (int i = 0; i < n; i++)
      if (s & (1 << i))
        f[s] += a[i + 1];
    f[s] /= __builtin_popcount(s);
    for (int t = (s - 1) & s; t; t = (t - 1) & s)
      f[s] = max(f[s], min(f[t], f[s - t]));
  }
  printf("%.10lf\\n", f[(1 << n) - 1]);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 16;
double dis[N][N], f[1 << N], x[N], y[N], a[N];
int n, m;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      dis[i][j] =
          sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
  for (int i = 0; i <= 1 << n; i++)
    f[i] = 1e18;
  f[0] = 0;
  for (int i = 0; i < 1 << n; i++)
    f[1 << i] = 0;
  for (int s = 0; s < 1 << n; s++) {
    for (int i = 0; i <= n - 1; i++)
      for (int j = 0; j <= n - 1; j++)
        if ((s & (1 << i)) && (!(s & (1 << j))))
          f[s | (1 << j)] = min(f[s | (1 << j)], f[s] + dis[i + 1][j + 1]);
  }
  for (int s = 0; s < 1 << n; s++) {
    f[s] = -f[s];
    for (int i = 0; i < n; i++)
      if (s & (1 << i))
        f[s] += a[i + 1];
    f[s] /= (double)__builtin_popcount(s);
    for (int t = (s - 1) & s; t; t = (t - 1) & s)
      f[s] = max(f[s], min(f[t], f[s - t]));
  }
  printf("%.10lf\\n", f[(1 << n) - 1]);
}