alexjercan/bugnet huggingface dataset:
Problem p01869 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(e) (e).begin(), (e).end()
typedef long long ll;
ll n;
vector<ll> tubo28;

map<ll, ll> dp;

void make(ll m, int digit) {
  if (m)
    tubo28.push_back(m);
  if (digit == 18) {
    return;
  }
  make(m * 10 + 2, digit + 1);
  make(m * 10 + 8, digit + 1);
}

ll dfs(ll n) {
  if (n == 1) {
    return 0;
  }
  if (dp.count(n))
    return dp[n];
  ll ret = -1;

  rep(i, tubo28.size()) {
    if (tubo28[i] > n)
      break;
    if (n % tubo28[i] == 0) {
      ll t = dfs(n / tubo28[i]);
      if (t >= 0)
        ret = max(ret, t + 1);
    }
  }

  return dp[n] = ret;
}

int main() {
  make(0, 0);
  sort(all(tubo28));
  // reverse(all(tubo28));
  // comp();
  cin >> n;
  ll ans = dfs(n);
  if (ans <= 0)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(e) (e).begin(), (e).end()
typedef long long ll;
ll n;
vector<ll> tubo28;

void make(ll m, int digit) {
  if (m)
    tubo28.push_back(m);
  if (digit == 18) {
    return;
  }
  make(m * 10 + 2, digit + 1);
  make(m * 10 + 8, digit + 1);
}

ll dfs(ll n) {
  if (n == 1) {
    return 0;
  }
  ll ret = -1;

  rep(i, tubo28.size()) {
    if (tubo28[i] > n)
      break;
    if (n % tubo28[i] == 0) {
      ll t = dfs(n / tubo28[i]);
      if (t >= 0)
        ret = max(ret, t + 1);
    }
  }

  return ret;
}

int main() {
  make(0, 0);
  sort(all(tubo28));
  // reverse(all(tubo28));
  // comp();
  cin >> n;
  ll ans = dfs(n);
  if (ans <= 0)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p01872 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
string S;
vector<int> U;
int p[11] = {6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2};
bool solve(string F) {
  int sum = 0;
  for (int i = 0; i < 11; i++) {
    sum += p[i] * (F[i] - '0');
  }
  int G = F[11] - '0';
  sum %= 11;
  if (sum <= 1)
    sum = 11;
  if ((11 - sum) == G)
    return true;
  return false;
}
int main() {
  cin >> S;
  int D = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '?')
      D = i;
  }
  for (int i = 0; i < 10; i++) {
    string T = S;
    T[D] = (char)('0' + i);
    if (solve(T) == true)
      U.push_back(i);
  }
  if (U.size() >= 2)
    cout << "MULTIPLE" << endl;
  else
    cout << U[0] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string S;
vector<string> U;
int p[11] = {2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6};
bool solve(string F) {
  int sum = 0;
  for (int i = 0; i < 11; i++) {
    sum += p[i] * (F[i] - '0');
  }
  int G = F[11] - '0';
  sum %= 11;
  if (sum <= 1)
    sum = 11;
  if (sum == G)
    return true;
  return false;
}
int main() {
  cin >> S;
  int D = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '?')
      D = i;
  }
  for (int i = 0; i < 10; i++) {
    string T = S;
    T[i] = (char)('0' + i);
    if (solve(T) == true)
      U.push_back(T);
  }
  if (U.size() >= 2)
    cout << "MULTIPLE" << endl;
  else
    cout << U[0] << endl;
  return 0;
}
Problem p01873 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int b[100001] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  sort(b, b + 100001);
  int k;
  k = *lower_bound(b, b + 100001, 1);
  // cout << k << endl;
  int co = 0;
  while (1) {
    if (co != 0) {
      int kk = 1;
      for (int i = 2; i * i <= k; i++) {
        if (k % i == 0) {
          kk = k / i;
          break;
        }
      }
      k = kk;
    }

    // cout << k << endl;
    if (k == 1)
      break;
    int f = 0;
    if (n % k != 0) {
      co++;
      continue;
    }
    for (int i = 0; i < n / k; i++) {
      if (i + n / k >= n)
        break;
      if (a[i + n / k] != a[i]) {
        f = 1;
        break;
      }
    }
    if (f == 0)
      break;
    co++;
  }
  cout << k << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int b[100001] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  sort(b, b + 100001);
  int k;
  k = *lower_bound(b, b + 100001, 1);
  // cout << k << endl;
  int co = 0;
  while (1) {
    if (co != 0) {
      int kk = 1;
      for (int i = 2; i * i <= k; i++) {
        if (k % i == 0) {
          kk = k / i;
          break;
        }
      }
      k = kk;
    }

    // cout << k << endl;
    if (k == 1)
      break;
    int f = 0;
    if (n % k != 0)
      continue;
    for (int i = 0; i < n / k; i++) {
      if (i + n / k >= n)
        break;
      if (a[i + n / k] != a[i]) {
        f = 1;
        break;
      }
    }
    if (f == 0)
      break;
    co++;
  }
  cout << k << endl;
  return 0;
}
Problem p01873 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)

vector<int> divisors(int x) {
  vector<int> ret;
  int p = 1;
  while ((long long)p * p <= x) {
    if (x % p == 0) {
      ret.push_back(p);
      ret.push_back(x / p);
    }
    p++;
  }
  return ret;
}

int N;

bool isvalid(int T, vector<int> s) {
  vector<int> ans;
  rep(i, T) ans.push_back(s[i]);
  for (int i = T; i < s.size(); i += T) {
    bool f = true;
    rep(j, T) {
      if (ans[j] != s[i + j])
        return false;
    }
  }
  return true;
}

int main() {

  cin >> N;
  vector<int> S(N);
  rep(i, N) { cin >> S[i]; }

  auto yakusu = divisors(N);
  sort(yakusu.begin(), yakusu.end());

  rep(i, yakusu.size()) {
    int T = yakusu[i];
    if (isvalid(T, S)) {
      cout << N / T << endl;
      return 0;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)

int main() {

  int N;
  cin >> N;
  int pos = 0, k = 1;
  vector<int> curr;

  int x;
  cin >> x;
  curr.push_back(x);

  REP(i, 1, N) {
    int x;
    cin >> x;
    //    for(auto && e: curr) { cout << e << ", "; } cout << endl;
    //    cout << "x: " << x << ", " << "curr["<<pos<<"]: " << curr[pos] << ",
    //    ";
    if (x == curr[pos]) {
      pos++;
      if (pos >= curr.size()) {
        pos = 0;
        k++;
      }
      //      cout << "::pos: " << pos << ", k: " << k << endl;
    } else {
      auto c = curr;
      rep(ii, k - 1) {
        rep(j, c.size()) { curr.push_back(c[j]); }
      }
      rep(j, pos) { curr.push_back(c[j]); }
      curr.push_back(x);
      pos = 0, k = 1;
      if (i == N - 1) {
        k = 1;
      }
      //      cout << "  pos: " << pos << ", k: " << k << endl;
    }
  }

  cout << k << endl;

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }
  set<int> s;
  for (int i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      s.insert(i);
      s.insert(N / i);
    }
  }
  int ans = 1;
  for (int k : s) {
    int t = N / k;
    bool f = true;
    for (int i = 0; i < k; ++i) {
      for (int j = i; j < N; j += k) {
        if (a[i] != a[j]) {
          f = false;
          break;
        }
      }
      if (!f)
        break;
    }
    if (f)
      ans = max(ans, t);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf = 1e9;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }
  set<int> s;
  for (int i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      s.insert(i);
      s.insert(N / i);
    }
  }
  int ans = 1;
  for (int k : s) {
    int t = N / k;
    bool f = true;
    for (int i = 0; i < t; ++i) {
      for (int j = i; j < N; j += k) {
        if (a[i] != a[j]) {
          f = false;
          break;
        }
      }
      if (!f)
        break;
    }
    if (f)
      ans = max(ans, t);
  }
  cout << ans << endl;
}
Problem p01873 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}

typedef long long ll;
int const inf = 1 << 29;

template <class T> vector<T> divisors(T x) {
  vector<T> ret;
  int p = 1;
  while ((ll)p * p <= x) {
    if (x % p == 0) {
      ret.push_back(p);
      ret.push_back(x / p);
    }
    p++;
  }
  return ret;
}

int main() {

  int N;
  cin >> N;
  vector<int> S(N);
  rep(i, N) { cin >> S[i]; }
  auto d = divisors(N);
  sort(all(d));
  for (auto T : d) {
    bool ok = 1;
    rep(i, N / T) {
      rep(j, T) { ok &= S[j] == S[i * T + j]; }
    }
    if (ok) {
      cout << N / T << endl;
      return 0;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template <class T1, class T2> inline bool minimize(T1 &a, T2 b) {
  return b < a && (a = b, 1);
}
template <class T1, class T2> inline bool maximize(T1 &a, T2 b) {
  return a < b && (a = b, 1);
}

typedef long long ll;
int const inf = 1 << 29;

template <class T> vector<T> divisors(T x) {
  vector<T> ret;
  int p = 1;
  while ((ll)p * p <= x) {
    if (x % p == 0) {
      ret.push_back(p);
      ret.push_back(x / p);
    }
    p++;
  }
  return ret;
}

int main() {

  int N;
  cin >> N;
  vector<int> S(N);
  rep(i, N) { cin >> S[i]; }
  auto d = divisors(N);
  for (auto T : d) {
    for (int i = T; i <= N; i += T) {
      bool ok = 1;
      rep(j, T) { ok &= S[j] == S[i + j]; }
      if (ok) {
        cout << N / T << endl;
        return 0;
      }
      break;
    }
  }

  cout << 1 << endl;

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

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)

template <class T1, class T2> void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <class T1, class T2> void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  int N, S[200002];
  cin >> N;
  rep(i, N) cin >> S[i];
  reps(i, 1, N + 1) {
    if (N % i)
      continue;
    bool flag = true;
    rep(j, N - i) if (S[j] != S[j + i]) flag = false;
    if (flag) {
      cout << N / i << endl;
      return 0;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)

template <class T1, class T2> void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <class T1, class T2> void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  int N, S[202];
  cin >> N;
  rep(i, N) cin >> S[i];
  if (N % 2) {
    cout << 1 << endl;
    return 0;
  }
  reps(i, 1, N + 1) {
    if (N % i)
      continue;
    bool flag = true;
    rep(j, N - i) if (S[j] != S[j + i]) flag = false;
    if (flag) {
      cout << N / i << endl;
      return 0;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, cnt = 1;
  cin >> n;
  int s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (i > 0) {
      if (s[i] != s[i % cnt]) {
        cnt = i + 1;
      }
    }
  }
  if (n % cnt == 0)
    cout << n / cnt << endl;
  else
    cout << 1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N;
int num[200000];
int ans = 0;
bool swt = true;

void calc(int check1, int check2, int point) {
  if (check1 == point + 1) {
    ans = check1;
    swt = false;
    return;
  }
  if (num[check1] == num[check2])
    calc(check1 + 1, check2 + 1, point);
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> num[i];

  for (int i = 1; i < N; i++) {
    if (swt)
      calc(0, i + 1, i);
    else
      break;
  }

  cout << N / ans << endl;
  return 0;
}
Problem p01873 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main() {

  int N;
  scanf("%d", &N);

  int *table = new int[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &table[i]);
  }

  bool FLG;
  int num;

  for (num = 1; num < N; num++) {
    if (N % num != 0)
      continue;
    FLG = true;
    for (int loc = 0; loc + num < N; loc++) {
      if (table[loc] != table[loc + num]) {
        FLG = false;
        break;
      }
    }
    if (FLG)
      break;
  }

  printf("%d\\n", N / num);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main() {

  int N;
  scanf("%d", &N);

  int *table = new int[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &table[i]);
  }

  bool FLG;
  int num;

  for (num = 1; num < N; num++) {
    FLG = true;
    for (int loc = 0; loc + num < N; loc++) {
      if (table[loc] != table[loc + num]) {
        FLG = false;
        break;
      }
    }
    if (FLG)
      break;
  }

  printf("%d\\n", N / num);

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

#include <bitset>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

inline int rev(int i, int N) { return N - i - 1; }

int main() {
  std::istream &c_in = cin;
  int N;
  c_in >> N;
  vector<int> sub;
  sub.resize(N / 2);

  for (int i = 0; i < N / 2; ++i) {
    c_in >> sub[i];
  }

  int count = 0;
  int j = N - N / 2 - 1;
  for (int i = N / 2; i < N; ++i) {
    int dat;
    c_in >> dat;
    sub[j] -= dat;
    count += (sub[j--] == 0);
  }
  bool b_same = (count == N / 2);

  int Q;
  c_in >> Q;

  for (int q = 0; q < Q; ++q) {
    int L, r, x;
    c_in >> L >> r >> x;
    if (x != 0) {
      //??°??????l????????????r???????????§??????????????????????´??????°???x????¶????
      // 1???l???r???N
      L--; // base 0
      r--; // base 0

      int s, t;
      if (r < N / 2) {
        s = L;
        t = r;
      } else if (L >= N / 2) {
        s = rev(r, N);
        t = rev(L, N);
        x = -x;
      } else {
        r = rev(r, N);
        if (L < r) {
          s = L;
          t = r - 1;
        } else {
          s = r;
          t = L - 1;
          x = -x;
        }
      }
      if (s <= t) {
        int *p = &sub[s];
        for (int i = s; i <= t; ++i, ++p) {
          int v = *p;
          bool pre = (v == 0);
          v += x;
          bool same = (v == 0);
          *p = v;
          if (pre != same) {
            count += same - pre;
          }
        }
        b_same = (count == N / 2);
      }
    }
    cout << (b_same ? '1' : '0') << endl;
  }
}

Error: TLE

Fixed submission:

#include <bitset>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

inline int rev(int i, int N) { return N - i - 1; }

int main() {
  std::istream &c_in = cin;
  int N;
  c_in >> N;
  vector<int> sub;
  sub.resize(N / 2);

  for (int i = 0; i < N / 2; ++i) {
    c_in >> sub[i];
  }

  int count = 0;
  int j = N - N / 2 - 1;
  for (int i = N / 2; i < N; ++i) {
    int dat;
    c_in >> dat;
    sub[j] -= dat;
    count += (sub[j--] == 0);
  }
  bool b_same = (count == N / 2);

  int Q;
  c_in >> Q;

  for (int q = 0; q < Q; ++q) {
    int L, r, x;
    c_in >> L >> r >> x;
    if (x != 0) {
      //??°??????l????????????r???????????§??????????????????????´??????°???x????¶????
      // 1???l???r???N
      L--; // base 0
      r--; // base 0

      int s, t;
      if (r < N / 2) {
        s = L;
        t = r;
      } else if (L >= N / 2) {
        s = rev(r, N);
        t = rev(L, N);
        x = -x;
      } else {
        r = rev(r, N);
        if (L < r) {
          s = L;
          t = r - 1;
        } else {
          s = r;
          t = L - 1;
          x = -x;
        }
      }
      if (s <= t) {
        int prec = 0;
        int samec = 0;
        int *p = &sub[s];
        for (int i = s; i <= t; ++i) {
          int s = *p;
          prec += (s == 0);
          s += x;
          samec += (s == 0);
          *p++ = s;
        }
        count = count - prec + samec;
        b_same = (count == N / 2);
      }
    }
    cout << (b_same ? '1' : '0') << endl;
  }
}
Problem p01878 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod = 1000000007;
const int tMAX = 5;

inline void init(mat &A, int n, int m) { A = mat(n, vec(m, 0)); }

inline mat add(mat A, mat B) {
  mat res = A;
  rep(i, A.size()) rep(j, A[i].size())(res[i][j] += B[i][j]) %= mod;
  return res;
}

inline mat mul(mat A, mat B) {
  mat res;
  init(res, A.size(), B[0].size());
  rep(i, A.size()) rep(j, B[0].size()) {
    rep(k, B.size()) res[i][j] += (A[i][k] * B[k][j]) % mod;
    res[i][j] %= mod;
  }
  return res;
}

inline mat pow_mat(mat &A, ll n) {
  if (n == 1LL)
    return A;
  mat B = pow_mat(A, n / 2), res = mul(B, B);
  if (n & 1)
    res = mul(A, res);
  return res;
}

ll N, K, C, T, tr;
ll a, b, t;
vec shuffle(50), perm(50);
mat perm_mat[10], dp[500100], tmp;
mat large_mat, thin_mat;

int main() {
  cin >> N >> K >> C >> T;

  rep(i, tMAX + 1) init(perm_mat[i], N, N);
  rep(i, N) perm[i] = i;

  rep(i, K) {
    cin >> a >> b >> t;
    rep(j, b) shuffle[j] = perm[j + a - 1];
    rep(j, a - 1) shuffle[b + j] = perm[j];
    for (int j = a + b - 1; j < N; j++)
      shuffle[j] = perm[j];
    rep(j, N) perm_mat[t][j][shuffle[j]]++;
  }

  rep(i, tMAX + 1) init(dp[i], N, N);
  rep(i, N) dp[0][i][i] = 1;

  rep(i, tMAX) rep(j, tMAX) {
    if (i + j + 1 <= tMAX) {
      tmp = mul(perm_mat[j + 1], dp[i]);
      dp[i + j + 1] = add(dp[i + j + 1], tmp);
    }
  }

  init(large_mat, N * tMAX, N * tMAX);
  rep(id, tMAX) {
    rep(i, N) rep(j, N) large_mat[i][j + id * N] = perm_mat[id + 1][i][j];
  }
  rep(i, N * (tMAX - 1)) large_mat[i + N][i] = 1;

  init(thin_mat, N * tMAX, N);
  rep(id, tMAX) {
    rep(i, N) rep(j, N) thin_mat[i + id * N][j] = dp[tMAX - 1 - id][i][j];
  }

  tmp = pow_mat(large_mat, T);
  cout << mul(tmp, thin_mat)[(tMAX - 1) * N][C - 1] << endl;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, vector<int>> P;
const ll mod = 1000000007;

ll N, K, C, T, tr;
ll a[100100], b[100100], t[100100];

int main() {
  cin >> N >> K >> C >> T;
  for (int i = 0; i < K; i++)
    cin >> a[i] >> b[i] >> t[i];

  vector<int> tmp(N), perm(N);
  for (int i = 0; i < N; i++)
    perm[i] = i + 1;

  stack<P> s;
  s.push(P(0, perm));

  ll res = 0;
  while (s.size()) {
    P p = s.top();
    s.pop();
    int cost = p.first;
    perm = p.second;

    if (cost == T && perm[0] == C) {
      res++;
      res %= mod;
      continue;
    }

    for (int i = 0; i < K; i++) {
      if (cost + t[i] <= T) {
        for (int j = 0; j < b[i]; j++)
          tmp[j] = perm[j + a[i] - 1];
        for (int j = 0; j < a[i] - 1; j++)
          tmp[b[i] + j] = perm[j];
        for (int j = a[i] + b[i] - 1; j < N; j++)
          tmp[j] = perm[j];

        s.push(P(cost + t[i], tmp));
      }
    }
  }

  cout << res << endl;
}
Problem p01880 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int N = 1005;
int a[N], b[N * N];
bool judge(int n) {
  int tmp = n % 10;
  n /= 10;
  while (n > 0) {
    if (n % 10 != tmp - 1)
      return false;
    tmp = n % 10;
    n /= 10;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int num = 0;
  for (int i = 1; i <= n - 1; i++)
    for (int j = i + 1; j <= n; j++)
      b[num++] = a[i] * a[j];

  sort(b, b + num);
  int nu = unique(b, b + num) - b;
  for (int i = nu - 1; i >= 0; i--) {
    if (judge(b[i]))
      return 0 * printf("%d\\n", b[i]);
  }
  printf("-1\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int N = 1005;
int a[N], b[N];
bool judge(int n) {
  int tmp = n % 10;
  n /= 10;
  while (n > 0) {
    if (n % 10 != tmp - 1)
      return false;
    tmp = n % 10;
    n /= 10;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int num = 0;
  for (int i = 1; i <= n - 1; i++)
    for (int j = i + 1; j <= n; j++)
      b[num++] = a[i] * a[j];

  sort(b, b + num);
  for (int i = num - 1; i >= 0; i--) {
    if (judge(b[i]))
      return 0 * printf("%d\\n", b[i]);
  }
  printf("-1\\n");
  return 0;
}