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

#include <bits/stdc++.h>
#define int long long
#define PB push_back
#define FI first
#define SE second
using namespace std;
static const int MAX_N = 1 << 17;
static const int inf = 1ll << 6;
typedef pair<int, int> PII;

int N;
vector<PII> V;

class Segment {
public:
  int dp[2 * MAX_N];
  int n;

  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    for (int i = 0; i < 2 * n - 1; ++i)
      dp[i] = -inf;
  }

  void update(int k, int a) {
    k += n - 1;
    dp[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dp[k] = max(dp[2 * k + 1], dp[2 * k + 2]);
    }
  }

  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return dp[k];
    else {
      int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
      int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      return max(vl, vr);
    }
  }
};

int res;

signed main() {
  cin >> N;
  Segment seg;
  seg.init(N);
  int MAX = N * (N + 1) / 2;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    V.PB(PII(a, -i));
  }
  sort(V.begin(), V.end());
  for (int i = 0; i < N; ++i) {
    int j = -V[i].SE;
    seg.update(j, V[i].FI);
    seg.update(
        j, max(seg.dp[j + seg.n - 1], seg.query(0, j, 0, 0, seg.n) + V[i].FI));
  }
  cout << MAX - seg.dp[0] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define PB push_back
#define FI first
#define SE second
using namespace std;
static const int MAX_N = 1 << 17;
static const int inf = 1ll << 6;
typedef pair<int, int> PII;

int N;
vector<PII> V;

class Segment {
public:
  int dp[MAX_N];
  int n;

  void init(int n_) {
    n = 1;
    while (n < n_)
      n *= 2;
    for (int i = 0; i < 2 * n - 1; ++i)
      dp[i] = -inf;
  }

  void update(int k, int a) {
    k += n - 1;
    dp[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dp[k] = max(dp[2 * k + 1], dp[2 * k + 2]);
    }
  }

  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return -inf;
    if (a <= l && r <= b)
      return dp[k];
    else {
      int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
      int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
      return max(vl, vr);
    }
  }
};

int res;

signed main() {
  cin >> N;
  Segment seg;
  seg.init(N);
  int MAX = N * (N + 1) / 2;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    V.PB(PII(a, -i));
  }
  sort(V.begin(), V.end());
  for (int i = 0; i < N; ++i) {
    int j = -V[i].SE;
    seg.update(j, V[i].FI);
    seg.update(
        j, max(seg.dp[j + seg.n - 1], seg.query(0, j, 0, 0, seg.n) + V[i].FI));
  }
  cout << MAX - seg.dp[0] << endl;
}
Problem p01545 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 100001

// Binary Indexed Tree (Fenwick Tree)
template <class T> class BIT {
public:
  vector<T> v;
  BIT(int n) : v(n + 1, 0) {}
  //[1,i]??????
  // e.g. [i,j]?????? : sum(j)-sum(i-1)
  T sum(int i) {
    T sum = 0;
    for (; i > 0; i -= i & -i)
      sum += v[i];
    return sum;
  }
  //[1,i]????????§???
  T query(int i) {
    T M = 0;
    for (; i > 0; i -= i & -i) {
      M = max(M, v[i]);
      // cout << "query i:" << i << " M:" << M << endl;
    }
    return M;
  }
  // v[i]??¨????????????????´??????´??°
  void update(int i, T x) {
    for (; i < v.size(); i += i & -i) {
      // cout << "update i:" << i << " x:" << x << " v.size():" << v.size() <<
      // endl;
      v[i] = max(v[i], x);
    }
  }
};

int main() {
  ll n;
  cin >> n;
  BIT<ll> BIT(n);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    BIT.update(x, BIT.query(x - 1) + x);
    // cout << endl;
    // for (int j = 1; j <= n; j++) {
    //	cout << BIT.v[j] << " ";
    // }
    // cout << endl;
  }

  cout << n * (n + 1) / 2 - BIT.query(n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
  int n;
  cin >> n;
  int S = 0;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    int X;
    scanf("%d", &X);
    x[i] = X;
    S += X;
  }

  vector<int> dp(n, 0);
  dp[n - 1] = x[n - 1];
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j < n; j++) {
      // cerr << x[i] << " " << x[j] << endl;
      if (x[j] > x[i]) {
        dp[i] = max(dp[i], x[i] + dp[j]);
        // cerr << " " << M[i] << " " << x[i] + M[j] << endl;
      }
    }
  }
  cout << S - *max_element(dp.begin(), dp.end()) << endl;
  return 0;
}
Problem p01549 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef set<int> S;
typedef S::iterator Sit;

int getNum(string a) {
  int res = 0;
  for (int i = 0; i < a.size(); i++)
    res = res * 10 + a[i] - '0';
  return res;
}

map<string, P> val;
vector<string> el;
int n;

int calc() {
  stack<S> stk;
  for (int i = 0; i < n; i++) {
    string e = el[i];
    S t;
    if (isdigit(e[0]))
      t.insert(getNum(e));
    else if (isalpha(e[0])) {
      int l = val[e].first, r = val[e].second;
      while (l <= r)
        t.insert(l++);
    } else {
      S B = stk.top();
      stk.pop();
      S A = stk.top();
      stk.pop();
      for (Sit i = A.begin(); i != A.end(); i++)
        for (Sit j = B.begin(); j != B.end(); j++) {
          int a = *i, b = *j, r;
          if (e[0] == '+')
            r = (a + b) % 256;
          if (e[0] == '-')
            r = (a - b + 256) % 256;
          if (e[0] == '*')
            r = (a * b) % 256;
          if (e[0] == '/') {
            if (!b)
              return 0;
            r = (a / b) % 256;
          }
          t.insert(r);
        }
    }
    stk.push(t);
  }
  return 1;
}

int main() {
  int m;
  cin >> m;
  for (int i = 0, a, b; i < m; i++) {
    string t;
    cin >> t >> a >> b;
    val[t] = P(a, b);
  }
  cin >> n;
  el.resize(n);
  for (int i = 0; i < n; i++)
    cin >> el[i];
  cout << (calc() ? "correct" : "error") << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int getNum(string a) {
  int res = 0;
  for (int i = 0; i < a.size(); i++)
    res = res * 10 + a[i] - '0';
  return res;
}

map<string, P> val;
vector<string> el;
int n;

set<stack<int>> S[101];
bool calc(stack<int> s, int idx) {
  if (idx == n || S[idx].count(s))
    return 0;
  S[idx].insert(s);

  string e = el[idx];
  if (isdigit(e[0])) {
    s.push(getNum(e));
    return calc(s, idx + 1);
  }

  if (isalpha(e[0])) {
    int l = val[e].first, r = val[e].second;
    for (int i = l; i <= r; i++) {
      s.push(i);
      if (calc(s, idx + 1))
        return 1;
      s.pop();
    }
    return 0;
  }

  int b = s.top();
  s.pop();
  int a = s.top();
  s.pop();
  int r;
  if (e[0] == '+')
    r = a + b;
  if (e[0] == '-')
    r = a - b;
  if (e[0] == '*')
    r = a * b;
  if (e[0] == '/') {
    if (b == 0)
      return 1;
    r = a / b;
  }
  s.push((r + 256) % 256);
  return calc(s, idx + 1);
}

int main() {
  int m;
  cin >> m;
  for (int i = 0, a, b; i < m; i++) {
    string t;
    cin >> t >> a >> b;
    val[t] = P(a, b);
  }
  cin >> n;
  el.resize(n);
  for (int i = 0; i < n; i++)
    cin >> el[i];
  cout << (!calc(stack<int>(), 0) ? "correct" : "error") << endl;
  return 0;
}
Problem p01549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef unsigned char uc;
int main() {
  int m;
  cin >> m;
  int l[m], r[m];
  map<string, int> ms;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s >> l[i] >> r[i];
    ms[s] = i;
  }
  int n;
  cin >> n;
  string ss[n];
  for (int i = 0; i < n; i++)
    cin >> ss[i];
  bool f = 0;
  time_t start = clock();
  srand((unsigned)time(NULL));
  while ((double)(clock() - start) / CLOCKS_PER_SEC < 1.7 && !f) {
    stack<uc> sc;
    for (int i = 0; !f && i < n; i++) {
      // cout<<i<<":"<<ss[i]<<endl;
      if (ms.find(ss[i]) != ms.end()) {
        int j = ms[ss[i]], k = l[j];
        if (r[j] != l[j])
          k += (rand() % (r[j] - l[j]));
        // cout<<ss[i]<<":"<<k<<endl;
        sc.push(k);
      } else if (isdigit(ss[i][0])) {
        uc a = 0;
        for (int j = 0; j < (int)ss[i].size(); j++)
          a = (uc)(a * 10 + ss[i][j] - '0');
        sc.push(a);
      } else {
        uc a, b;
        b = sc.top();
        sc.pop();
        a = sc.top();
        sc.pop();
        if (ss[i] == "+")
          sc.push(a + b);
        if (ss[i] == "-")
          sc.push(a - b);
        if (ss[i] == "*")
          sc.push(a * b);
        if (ss[i] == "/") {
          if (b)
            sc.push(a / b);
          else {
            f = 1;
            break;
          }
        }
      }
    }
  }
  cout << (!f ? "correct" : "error") << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned char uc;
int main() {
  int m;
  cin >> m;
  int l[m], r[m];
  map<string, int> ms;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s >> l[i] >> r[i];
    ms[s] = i;
  }
  int n;
  cin >> n;
  string ss[n];
  for (int i = 0; i < n; i++)
    cin >> ss[i];
  bool f = 0;
  time_t start = clock();
  srand((unsigned)time(NULL));
  while ((double)(clock() - start) / CLOCKS_PER_SEC < 1.7 && !f) {
    stack<uc> sc;
    for (int i = 0; !f && i < n; i++) {
      // cout<<i<<":"<<ss[i]<<endl;
      if (ms.find(ss[i]) != ms.end()) {
        int j = ms[ss[i]], k = (l[j] + (rand() % (r[j] - l[j])));
        // cout<<ss[i]<<":"<<k<<endl;
        sc.push(k);
      } else if (isdigit(ss[i][0])) {
        uc a = 0;
        for (int j = 0; j < (int)ss[i].size(); j++)
          a = (uc)(a * 10 + ss[i][j] - '0');
        sc.push(a);
      } else {
        uc a, b;
        b = sc.top();
        sc.pop();
        a = sc.top();
        sc.pop();
        if (ss[i] == "+")
          sc.push(a + b);
        if (ss[i] == "-")
          sc.push(a - b);
        if (ss[i] == "*")
          sc.push(a * b);
        if (ss[i] == "/") {
          if (b)
            sc.push(a / b);
          else {
            f = 1;
            break;
          }
        }
      }
    }
  }
  cout << (!f ? "correct" : "error") << endl;
  return 0;
}
Problem p01552 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

char buf[50010];

int main() {
  string s;
  getline(cin, s);
  const char *ptr = s.c_str();

  vector<string> key;
  int d = 0;
  while (sscanf(ptr, ".%[^.]%n", buf, &d) > 0) {
    ptr += d;
    key.push_back(buf);
  }

  int m = 0;
  int prev = -1;
  int indent = -1;
  int k = 0;
  while (true) {
    getline(cin, s);
    if (s.size() < 2)
      break;

    ptr = s.c_str();
    sscanf(ptr, " %n%[^:]:%n", &indent, buf, &d);

    if (indent <= prev)
      break;

    if (m == -1)
      m = indent;

    if (m == indent && key[k] == buf) {
      m = -1;
      prev = indent;

      if (++k == key.size()) {
        if (s[d] == ' ') {
          cout << "string \\"" << s.substr(d + 1) << "\\"\\n";
        } else {
          cout << "object\\n";
        }

        return 0;
      }
    }
  }

  cout << "no such property\\n";
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

char buf[5010];

int main() {
  string s;
  getline(cin, s);
  const char *ptr = s.c_str();

  vector<string> key;
  int d = 0;
  while (sscanf(ptr, ".%[^.]%n", buf, &d) > 0) {
    ptr += d;
    key.push_back(buf);
  }

  int m = 0;
  int prev = -1;
  int indent = -1;
  int k = 0;
  while (true) {
    buf[0] = '\\0';

    getline(cin, s);
    if (s.size() < 2)
      break;

    ptr = s.c_str();
    if (sscanf(ptr, " %n%[^:]:%n", &indent, buf, &d) < 1)
      break;

    if (indent <= prev)
      break;

    if (m == -1)
      m = indent;

    if (m == indent && key[k] == buf) {
      m = -1;
      prev = indent;

      if (++k == key.size()) {
        if (s[d] == ' ') {
          cout << "string \\"" << s.substr(d + 1) << "\\"\\n";
        } else {
          cout << "object\\n";
        }

        return 0;
      }
    }
  }

  cout << "no such property\\n";
}
Problem p01552 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
vector<string> str;
vector<int> cnt;
string key;
int pos;

bool check(string a, int x, int y) {
  int ima = pos, i = 0, j = 0;
  if (cnt[x] <= cnt[y] && pos != 1)
    return 0;
  while (key[ima] == a[i])
    ima++, i++;
  if ((key[ima] == '.' || !key[ima]) && a[i] == ':') {
    pos = ima + 1;
    return 1;
  }
  return 0;
}

string bnf() {
  int idx = 0;
  int par = 0;
  while (pos < (int)key.size()) {
    while (idx < (int)str.size() && !check(str[idx], idx, par))
      idx++;
    if (idx == (int)str.size())
      return "no such property";
    par = idx;
  }

  if (str[idx][str[idx].size() - 1] == ':')
    return "object";
  string ans = "string \\"";
  int f = 0;
  for (int i = 0; i < str[idx].size(); i++) {
    if (str[idx][i] == ':')
      f = 1;
    else if (f == 1 && str[idx][i] == ' ')
      f = 2;
    else if (f == 2)
      ans += str[idx][i];
  }
  ans += "\\"";
  return ans;
}

int main() {
  cin >> key;
  string a;
  getline(cin, a);
  while (getline(cin, a))
    str.push_back(a);
  for (int i = 0; i < str.size(); i++) {
    int j = 0;
    while (str[i][j] == ' ')
      j++;
    cnt.push_back(j + 1);
    str[i] = str[i].substr(j, str[i].size() - j);
  }
  pos = 1;
  cout << bnf() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<string> str;
string key;
int pos;

bool check(string a, string b) {
  int ima = pos, i = 0, j = 0;
  while (a[i] == ' ')
    i++;
  while (b[i] == ' ')
    j++;
  if (pos != 1 && i <= j)
    return 0;
  while (key[ima] == a[i])
    ima++, i++;
  if ((key[ima] == '.' || !key[ima]) && a[i] == ':') {
    pos = ima + 1;
    return 1;
  }
  return 0;
}

string bnf() {
  int idx = 0;
  string par;
  while (pos < (int)key.size()) {
    // idx=0;
    while (idx < (int)str.size() && !check(str[idx], par))
      idx++;
    if (idx == (int)str.size())
      return "no such property";
    par = str[idx];
  }

  if (str[idx][str[idx].size() - 1] == ':')
    return "object";
  string ans = "string \\"";
  int f = 0;
  for (int i = 0; i < str[idx].size(); i++) {
    if (str[idx][i] == ':')
      f = 1;
    else if (f == 1 && str[idx][i] == ' ')
      f = 2;
    else if (f == 2)
      ans += str[idx][i];
  }
  ans += "\\"";
  return ans;
}

int main() {
  cin >> key;
  string a;
  getline(cin, a);
  while (getline(cin, a))
    str.push_back(a);
  pos = 1;
  cout << bnf() << endl;
  return 0;
}
Problem p01553 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
const int MOD = 1000000007;
ll dp[210][210];
int main() {
  int n;
  scanf("%d", &n);
  string s = "";
  rep(i, n) {
    char c;
    cin >> c;
    if (c == '-')
      continue;
    s += c;
  }
  n = s.size();
  if (!n)
    goto one;
  memset(dp, 0, sizeof(dp));
  if (s[0] == 'D')
    goto fail;
  dp[0][1] = 1;
  REP(i, 1, n) {
    rep(j, i + 2) {
      if (s[i] == 'D') {
        dp[i][j] += (dp[i - 1][j] * j) % MOD;
        dp[i][j] += (dp[i - 1][j + 1] * (j + 1) * (j + 1)) % MOD;
      } else {
        dp[i][j] += dp[i - 1][j - 1];
        dp[i][j] += (dp[i - 1][j] * j) % MOD;
      }
      dp[i][j] %= MOD;
    }
  }
  printf("%d\\n", dp[n - 1][0]);
  return 0;
fail:
  puts("0");
  return 0;
one:
  puts("1");
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
const int MOD = 1000000007;
ll dp[210][210];
int main() {
  int n;
  scanf("%d", &n);
  string s = "";
  rep(i, n) {
    char c;
    cin >> c;
    if (c == '-')
      continue;
    s += c;
  }
  n = s.size();
  memset(dp, 0, sizeof(dp));
  if (s[0] == 'D')
    goto fail;
  dp[0][1] = 1;
  REP(i, 1, n) {
    rep(j, i + 2) {
      if (s[i] == 'D') {
        dp[i][j] += (dp[i - 1][j] * j) % MOD;
        dp[i][j] += (dp[i - 1][j + 1] * (j + 1) * (j + 1)) % MOD;
      } else {
        dp[i][j] += dp[i - 1][j - 1];
        dp[i][j] += (dp[i - 1][j] * j) % MOD;
      }
      dp[i][j] %= MOD;
    }
  }
  printf("%d\\n", dp[n - 1][0]);
  return 0;
fail:
  puts("0");
  return 0;
}
Problem p01553 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void solve() {
  int n;
  cin >> n;
  vector<char> c(n);
  rep(i, 0, n) cin >> c[i];

  int64_t mod = 1e9 + 7;
  vector<vector<int64_t>> dp(n, vector<int64_t>(n + 1));
  if (c[0] == '-')
    dp[0][1] = 1;
  else
    dp[0][0] = 1;
  rep(i, 1, n) {
    rep(j, 0, n + 1) {
      if (c[i] == '-') {
        if (j - 1 >= 0)
          dp[i][j] = dp[i - 1][j - 1];
      }
      if (c[i] == 'U') {
        if (j - 1 >= 0)
          dp[i][j] = dp[i - 1][j - 1] * (i - j + 1);
        dp[i][j] += dp[i - 1][j];
      }
      if (c[i] == 'D') {
        if (j - 2 >= 0)
          dp[i][j] = dp[i - 1][j - 2] * (i - j + 2) * (i - j + 2);
        if (j - 1 >= 0)
          dp[i][j] += dp[i - 1][j - 1] * (i - j + 1);
      }
      dp[i][j] %= mod;
    }
  }
  cout << dp[n - 1][n] << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void solve() {
  int n;
  cin >> n;
  vector<vector<int>> graph(n);
  rep(i, 0, n) {
    char c;
    cin >> c;
    if (c == '-')
      graph[i].push_back(i);
    if (c == 'U')
      rep(j, i + 1, n) graph[i].push_back(j);
    if (c == 'D')
      rep(j, 0, i) graph[i].push_back(j);
  }

  vector<int> ord;
  rep(i, 0, n / 2) {
    ord.push_back(i);
    ord.push_back(n - i - 1);
  }
  rep(i, 0, n) if (find(ord.begin(), ord.end(), i) == ord.end())
      ord.push_back(i);

  const int64_t mod = 1e9 + 7;
  vector<bool> used(n);
  function<int64_t(int i)> rec = [&](int i) {
    if (i == n)
      return int64_t(1);
    int64_t res = 0;
    int u = ord[i];
    for (int v : graph[u]) {
      if (used[v])
        continue;
      used[v] = true;
      res = (res + rec(i + 1)) % mod;
      used[v] = false;
    }
    return res;
  };

  cout << rec(0) << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();
  return 0;
}
Problem p01553 (C++) — buggy submission, verdict: Runtime Error

class in {
  struct It {
    int it;
    const bool rev;
    explicit constexpr It(int it_, bool rev = false) : it(it_), rev(rev) {}
    int operator*() { return it; }
    bool operator!=(It &r) { return it != r.it; }
    void operator++() { rev ? --it : ++it; }
  };
  const It i, n;

public:
  explicit constexpr in(int n) : i(0), n(n < 0 ? 0 : n) {}
  explicit constexpr in(int i, int n) : i(i, n < i), n(n) {}
  const It &begin() { return i; }
  const It &end() { return n; }
};

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

using i64 = long long;
const i64 MOD = 1e9 + 7;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<char> a(n);
  for (auto &x : a)
    cin >> x;
  vector<i64> dp(n + 1, 0LL);
  dp[0] = 1LL;
  for (int i : in(n)) {
    char c = a[i];
    if (c == '-')
      continue;
    vector<i64> dp_(n + 1, 0LL);
    if (c == 'D') {
      for (i64 j : in(i + 2)) {
        (dp_[j] += dp[j] * j) %= MOD;
        (dp_[j] += dp[j + 1] * (j + 1) * (j + 1)) %= MOD;
      }
    } else {
      for (i64 j : in(i + 2)) {
        if (j > 0)
          (dp_[j] += dp[j - 1]) %= MOD;
        (dp_[j] += dp[j] * j) %= MOD;
      }
    }
    dp = dp_;
  }
  cout << dp[0] << endl;
  return 0;
}

Error: 0

Fixed submission:

class in {
  struct It {
    int it;
    const bool rev;
    explicit constexpr It(int it_, bool rev = false) : it(it_), rev(rev) {}
    int operator*() { return it; }
    bool operator!=(It &r) { return it != r.it; }
    void operator++() { rev ? --it : ++it; }
  };
  const It i, n;

public:
  explicit constexpr in(int n) : i(0), n(n < 0 ? 0 : n) {}
  explicit constexpr in(int i, int n) : i(i, n < i), n(n) {}
  const It &begin() { return i; }
  const It &end() { return n; }
};

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

using i64 = long long;
const i64 MOD = 1e9 + 7;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<char> a(n);
  for (auto &x : a)
    cin >> x;
  vector<i64> dp(n, 0LL);
  dp[0] = 1LL;
  for (int i : in(n)) {
    char c = a[i];
    if (c == '-')
      continue;
    vector<i64> dp_(n, 0LL);
    if (c == 'D') {
      for (i64 j : in(i + 2)) {
        (dp_[j] += dp[j] * j) %= MOD;
        (dp_[j] += dp[j + 1] * (j + 1) * (j + 1)) %= MOD;
      }
    } else {
      for (i64 j : in(i + 2)) {
        if (j > 0)
          (dp_[j] += dp[j - 1]) %= MOD;
        (dp_[j] += dp[j] * j) %= MOD;
      }
    }
    dp = dp_;
  }
  cout << dp[0] << endl;
  return 0;
}