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

#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
using ll = long long;
int dd[] = {0, 1, 0, -1, 0}; // →↓←↑

void solve() {
  string S, T;
  cin >> S >> T;

  string B = T;

  int cnt = 0;
  while (true) {
    // judge
    int s = 0, b = 0;
    while (b < B.size()) {
      if (s == S.size()) {
        cout << cnt << endl;
        return;
      }
      if (S[s] == B[b]) {
        b++;
      }
      s++;
    }
    cnt++;

    // next
    string tmp = B;
    for (int i = 0; i < T.size(); i++) {
      tmp += B[i] + B;
      if (tmp.size() > S.size()) {
        cout << cnt << endl;
        return;
      }
    }
    B = tmp;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Error: MLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
using ll = long long;
int dd[] = {0, 1, 0, -1, 0}; // →↓←↑

void solve() {
  string S, T;
  cin >> S >> T;

  string B = T;

  int cnt = 0;
  while (true) {
    // judge
    int s = 0, b = 0;
    while (b < B.size()) {
      if (s == S.size()) {
        cout << cnt << endl;
        return;
      }
      if (S[s] == B[b]) {
        b++;
      }
      s++;
    }
    cnt++;

    // next
    string tmp = B;
    for (int i = 0; i < T.size(); i++) {
      tmp += B[i] + B;
    }
    if (tmp.size() > S.size()) {
      cout << cnt << endl;
      return;
    }
    B = tmp;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02127 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

bool match(const string &s, const string &t) {
  // cerr << t << endl;
  int idx = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (t[idx] == s[i])
      idx++;

    if (idx == t.size())
      return true;
  }

  return false;
}

int main() {
  string s, t;
  cin >> s >> t;

  int ans = 0;
  string T = t;
  while (match(s, T)) {
    ans++;
    if ((int64_t)T.size() * (t.size() + 1) + t.size() > s.size())
      break;
    string nT = T;
    for (int i = 0; i < t.size(); ++i) {
      nT += t[i] + T;
    }

    T = nT;
  }

  cout << ans << endl;
}


Error: MLE

Fixed submission:

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

bool match(const string &s, const string &t) {
  // cerr << t << endl;
  int idx = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (t[idx] == s[i])
      idx++;

    if (idx == t.size())
      return true;
  }

  return false;
}

int main() {
  string s, t;
  cin >> s >> t;

  int ans = 0;
  string T = t;
  while (match(s, T)) {
    string nT = T;
    for (int i = 0; i < t.size(); ++i) {
      nT += t[i] + T;
    }

    T = nT;

    ans++;
  }

  cout << ans << endl;
}
Problem p02127 (C++) — buggy submission, verdict: Memory Limit Exceeded

#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, T;

void dfs(string &p, ll d) {
  if (d == 0)
    return;
  dfs(p, d - 1);
  REP(i, 0, T.length()) {
    p += T[i];
    dfs(p, d - 1);
  }
}

bool sub(string &p) {
  ll cnt = 0;
  REP(i, 0, S.length()) {
    if (S[i] == p[cnt])
      cnt++;
  }
  return cnt == p.size();
}

int main(void) {
  cin >> S >> T;

  ll ans = 0;
  ll sum = 0;
  for (ll i = 1;; i++) {
    sum = sum * (T.length() + 1) + T.length();
    if (sum > S.length())
      break;
    string p = "";
    dfs(p, i);
    // cerr << p << endl;

    if (sub(p))
      ans = i;
  }
  cout << ans << endl;
}


Error: MLE

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, T;

void dfs(string &p, ll d) {
  if (d == 0)
    return;
  dfs(p, d - 1);
  REP(i, 0, T.length()) {
    p += T[i];
    dfs(p, d - 1);
  }
}

bool sub(string &p) {
  ll cnt = 0;
  REP(i, 0, S.length()) {
    if (S[i] == p[cnt])
      cnt++;
  }
  return cnt == p.size();
}

int main(void) {
  cin >> S >> T;

  ll ans = 0;
  for (ll i = 1;; i++) {
    string p = "";
    dfs(p, i);
    // cerr << p << endl;
    if (p.length() > S.length())
      break;

    if (sub(p))
      ans = i;
  }
  cout << ans << endl;
}
Problem p02127 (C++) — buggy submission, verdict: Memory Limit Exceeded

#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;

string s;
string ns;

void solve(string S, string T) {
  s = T;
  int ans = 0;
  while (s.size() <= S.size()) {
    bool flag = false;
    int i = 0;
    for (char c : S) {
      if (s[i] == c) {
        i++;
        if (i >= s.size()) {
          flag = true;
          break;
        }
      }
    }
    if (flag == false) {
      std::cout << ans << std::endl;
      return;
    }
    ans++;
    ns = "";
    if ((T.size() + 1) * s.size() + T.size() > S.size()) {
      break;
    }
    for (int i = 0; i < T.size(); i++) {
      ns += s;
      ns.push_back(T[i]);
    }
    ns += s;
    s = ns;
  }
  std::cout << ans << std::endl;
  return;
}

int main() {

  string S, T;

  std::cin >> S >> T;
  solve(S, T);

  return 0;
}


Error: MLE

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;

string s;
string ns;

void solve(string S, string T) {
  s = T;
  int ans = 0;
  while (s.size() <= S.size()) {
    bool flag = false;
    int i = 0;
    for (char c : S) {
      if (s[i] == c) {
        i++;
        if (i >= s.size()) {
          flag = true;
          break;
        }
      }
    }
    if (flag == false) {
      std::cout << ans << std::endl;
      return;
    }
    ans++;
    ns = "";
    // ns.resize((T.size()+1)*s.size() + T.size());
    for (int i = 0; i < T.size(); i++) {
      ns += s;
      ns.push_back(T[i]);
    }
    ns += s;
    s = ns;
  }
  std::cout << ans << std::endl;
}

int main() {

  string S, T;

  std::cin >> S >> T;
  solve(S, T);

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

bool ok(string &s, string &t) {
  int now = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == t[now]) {
      now++;
      if (now == t.length())
        return true;
    }
  }
  return false;
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<string> tt(100, "");
  for (int i = 1; i < 100; i++) {
    tt[i] = tt[i - 1];
    for (int j = 0; j < t.length(); j++) {
      tt[i] += string(1, t[j]);
      tt[i] += tt[i - 1];
      if (tt[i].length() > s.length()) {
        cout << i - 1 << endl;
        return 0;
      }
    }
    // cout << tt[i] << endl;
    if (!ok(s, tt[i])) {
      cout << i - 1 << endl;
      return 0;
    }
  }
  return 0;
}


Error: MLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

bool ok(string &s, string &t) {
  int now = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == t[now]) {
      now++;
      if (now == t.length())
        return true;
    }
  }
  return false;
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<string> tt(100, "");
  for (int i = 1; i < 100; i++) {
    tt[i] = tt[i - 1];
    for (int j = 0; j < t.length(); j++) {
      tt[i] += string(1, t[j]);
      tt[i] += tt[i - 1];
    }
    // cout << tt[i] << endl;
    if (!ok(s, tt[i])) {
      cout << i - 1 << endl;
      return 0;
    }
  }
  return 0;
}
Problem p02128 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<lint, pii> plpii;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int N = 1010;
const lint inf = 1e16;

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int mi = 1e8;
  vector<pii> pts(n + 2);
  pts[0] = pii(1, 1);
  pts[1] = pii(w, h);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    pts[i + 2] = pii(x, y);
  }
  priority_queue<plpii, vector<plpii>, greater<plpii>> que;
  vector<vector<lint>> dis(n + 2, vector<lint>(N, inf));
  rep(i, n) {
    int d = abs(pts[i + 2].first - 1) + abs(pts[i + 2].second - 1);
    que.push(plpii(d, pii(i + 2, d)));
  }
  while (!que.empty()) {
    plpii top = que.top();
    que.pop();
    lint d = top.first;
    pii xy = top.second;
    int x = xy.first, y = xy.second;
    if (dis[x][y] <= d)
      continue;
    dis[x][y] = d;
    rep(i, n + 2) {
      if (i == x || i == 0)
        continue;
      int c =
          abs(pts[i].first - pts[x].first) + abs(pts[i].second - pts[x].second);
      c = max(0, i == 1 ? c - y : (c - y - 1));
      if (c >= N)
        continue;
      int nx = i;
      int ny = i == 1 ? 0 : c;
      if (dis[nx][ny] <= d + c)
        continue;
      dis[nx][ny] = d + c + 1;
      que.push(plpii(d + c, pii(nx, ny)));
    }
  }
  cout << dis[1][0] << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<lint, pii> plpii;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int N = 1010;
const lint inf = 1e16;

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  int mi = 1e8;
  vector<pii> pts(n + 2);
  pts[0] = pii(1, 1);
  pts[1] = pii(w, h);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    pts[i + 2] = pii(x, y);
  }
  priority_queue<plpii, vector<plpii>, greater<plpii>> que;
  vector<vector<lint>> dis(n + 2, vector<lint>(N, inf));
  rep(i, n) {
    int d = abs(pts[i + 2].first - 1) + abs(pts[i + 2].second - 1);
    que.push(plpii(d, pii(i + 2, d)));
  }
  while (!que.empty()) {
    plpii top = que.top();
    que.pop();
    lint d = top.first;
    pii xy = top.second;
    int x = xy.first, y = xy.second;
    if (dis[x][y] <= d)
      continue;
    dis[x][y] = d;
    rep(i, n + 2) {
      if (i == x || i == 0)
        continue;
      int c =
          abs(pts[i].first - pts[x].first) + abs(pts[i].second - pts[x].second);
      c = max(0, i == 1 ? c - y : (c - y - 1));
      if (c >= N)
        continue;
      que.push(plpii(d + c, pii(i, i == 1 ? 0 : c)));
    }
  }
  cout << dis[1][0] << endl;
}
Problem p02129 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1e9 + 1)

vector<int> getperm() {
  int w;
  cin >> w;
  vector<int> ret = vector<int>{0, 1, 2};

  rep(i, w) {
    int p;
    cin >> p;
    if (p == 0)
      swap(ret[0], ret[1]);
    else
      swap(ret[1], ret[2]);
  }

  return ret;
}

vector<int> f(vector<int> origin, vector<int> comb) {
  vector<int> ret(3);
  rep(i, 3) { ret[i] = origin[comb[i]]; }

  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> v;
  map<vector<int>, int> mp;
  rep(i, n) {
    vector<int> t = getperm();
    if (mp[t] < 2) {
      if (mp[t] == 0 or t == vector<int>{2, 0, 1} or
          t == vector<int>{1, 2, 0}) {
        v.pb(t);
      }
    }
    mp[t]++;
  }

  assert(v.size() <= 8);

  if (mp[vector<int>{2, 0, 1}] >= 3 or mp[vector<int>{1, 2, 0}] >= 3 or
      mp[vector<int>{2, 1, 0}] >= 2 or mp[vector<int>{1, 0, 2}] >= 2 or
      mp[vector<int>{0, 1, 2}] >= 2 or mp[vector<int>{0, 2, 1}] >= 2) {
    cout << "yes" << endl;
    return 0;
  }

  sort(all(v));

  do {
    vector<int> t = v[0];
    if (t == vector<int>{0, 1, 2}) {
      cout << "yes" << endl;
      return 0;
    }
    for (int i = 1; i < v.size(); i++) {
      t = f(t, v[i]);
      if (t == vector<int>{0, 1, 2}) {
        cout << "yes" << endl;
        return 0;
      }
    }
  } while (next_permutation(all(v)));

  cout << "no" << endl;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1e9 + 1)

vector<int> getperm() {
  int w;
  cin >> w;
  vector<int> ret = vector<int>{0, 1, 2};

  rep(i, w) {
    int p;
    cin >> p;
    if (p == 0)
      swap(ret[0], ret[1]);
    else
      swap(ret[1], ret[2]);
  }

  return ret;
}

vector<int> f(vector<int> origin, vector<int> comb) {
  vector<int> ret(3);
  rep(i, 3) { ret[i] = origin[comb[i]]; }

  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> v;
  map<vector<int>, int> mp;
  rep(i, n) {
    vector<int> t = getperm();
    if (mp[t] > 2)
      continue;
    if (mp[t] == 0 or t == vector<int>{2, 0, 1} or t == vector<int>{1, 2, 0}) {
      v.pb(t);
      mp[t]++;
    }
  }

  assert(v.size() <= 8);

  sort(all(v));

  do {
    vector<int> t = v[0];
    if (t == vector<int>{0, 1, 2}) {
      cout << "yes" << endl;
      return 0;
    }
    for (int i = 1; i < v.size(); i++) {
      t = f(t, v[i]);
      if (t == vector<int>{0, 1, 2}) {
        cout << "yes" << endl;
        return 0;
      }
    }
  } while (next_permutation(all(v)));

  cout << "no" << endl;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, fib[45] = {1, 1};
  cin >> n;
  for (int i = 2; i <= n; i++)
    fib[i] = fib[i - 1] + fib[i - 2];
  cout << fib[n];
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int fib(int n) {
  if (n <= 1)
    return 1;
  return fib(n - 1) + fib(n - 2);
}

int main() {
  int n;
  cin >> n;
  int ans;
  ans = fib(n);
  cout << ans;
  cout << endl;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int TwicePreviousValue = 1;
int PreviousValue = 1;

int Fibonacci(const int &n) {
  if (n == 0)
    return TwicePreviousValue;
  if (n == 1)
    return PreviousValue;
  int CurrentValue = TwicePreviousValue + PreviousValue;
  for (int i = 2; i < n; i++) {
    int TemporaryValue = PreviousValue;
    CurrentValue += PreviousValue;
    PreviousValue += TwicePreviousValue;
    TwicePreviousValue = TemporaryValue;
  }
  return CurrentValue;
}

int main() {
  int n;
  cin >> n;
  cout << Fibonacci(n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int Fibonacci(const int &n) {
  if (n == 0 || n == 1) {
    return 1;
  } else {
    return Fibonacci(n - 1) + Fibonacci(n - 2);
  }
}

int main() {
  int n;
  cin >> n;
  cout << Fibonacci(n) << endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int x, y;
  int F[50];
  F[0] = F[1] = 1;
  for (int i = 2; i < 50; i++)
    F[i] = F[i - 1] + F[i - 2];

  cin >> x;
  cout << F[x] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int fibo(int x) {
  int a;
  if (x == 0)
    return 1;
  if (x == 1)
    return 1;
  a = fibo(x - 1) + fibo(x - 2);
  return a;
}

int main() {
  int x, y;

  cin >> x;

  y = fibo(x);

  cout << y << endl;

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

#include <cstdio>
#include <iostream>

using namespace std;

int F[50];

int fib(int n) {

  if (n == 0 || n == 1)
    return 1;
  if (F[n] != 0)
    return F[n];

  F[n] = fib(n - 1) + fib(n - 2);

  return F[n];
}

int main() {

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

  for (int i = 0; i < n; ++i) {
    F[i] = 0;
  }

  cout << fib(n) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int fib(int n) {

  if (n == 0 || n == 1)
    return 1;

  return fib(n - 1) + fib(n - 2);
}

int main() {

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

  cout << fib(n) << endl;

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

#include <iostream>
#include <map>

std::pair<int, int> FibonacciPair(int Index) {
  if (Index == 0)
    return std::make_pair(0, 1);
  if (Index == 1)
    return std::make_pair(1, 1);
  std::pair<int, int> Prev = FibonacciPair(Index - 1);
  return std::make_pair(Prev.second, Prev.first + Prev.second);
}

int FibonacciNumber(int Index) { return FibonacciPair(Index).second; }

int main() {
  int Index;
  std::cin >> Index;
  std::cout << FibonacciNumber(Index) << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int FibonacciNumber(int Index) {
  if (Index == 0)
    return 1;
  if (Index == 1)
    return 1;
  return FibonacciNumber(Index - 1) + FibonacciNumber(Index - 2);
}

int main() {
  int Index;
  std::cin >> Index;
  std::cout << FibonacciNumber(Index) << std::endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define MAX 50

using namespace std;

int m_fibo(int n) {
  static int ans[MAX];
  if (n == 0 || n == 1)
    ans[n] = 1;
  if (ans[n] > 0)
    return ans[n];
  return ans[n] = m_fibo(n - 1) + m_fibo(n - 2);
}

int main() {
  int n;
  cin >> n;
  cout << m_fibo(n) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int fibo(int n) {
  if (n < 2)
    return 1;
  return fibo(n - 1) + fibo(n - 2);
}

int main() {
  int n;
  cin >> n;
  cout << fibo(n) << endl;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int fib(int n);

int memo[45];

int main() {
  int n;

  // 入力
  cin >> n;

  // 出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n) {

  if (n == 0)
    return 1;
  else if (n == 1)
    return 1;
  else if (memo[n] != 0)
    return memo[n];
  else
    return memo[n] = fib(n - 1) + fib(n - 2);
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int fib(int n);

int main() {
  int n;

  // 入力
  cin >> n;

  // 出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n) {
  /*　演習　*/
  if (n == 0)
    return 1;
  else if (n == 1)
    return 1;
  else
    return fib(n - 1) + fib(n - 2);
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int fib(int n);

int memo[45];

int main() {
  int n;

  // 入力
  cin >> n;

  // 出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n) {

  if (n == 0) {
    return 1;
  } else if (n == 1) {
    return 1;
  } else if (memo[n] != 0) {
    return memo[n];
  } else {
    return memo[n] = fib(n - 1) + fib(n - 2);
  }
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int fib(int n);

int memo[45];

int main() {
  int n;

  // 入力
  cin >> n;

  // 出力
  cout << fib(n) << endl;

  return 0;
}

int fib(int n) {

  if (n == 0) {
    return 1;
  } else if (n == 1) {
    return 1;
  } else if (memo[n] != 0) {
    return memo[n];
  } else {
    return fib(n - 1) + fib(n - 2);
  }
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
  return a > b;
}
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
  return a < b;
}
template <typename T> inline void print(const T &x, string s = "\\n") {
  cout << x << s;
}
template <typename T> inline void print(const vector<T> &v, string s = " ") {
  if (!v.size())
    puts("");
  rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\\n" : s);
}
inline bool inside(int y, int x, int H, int W) {
  return 0 <= y && y < H && 0 <= x && x < W;
}
inline lint in() {
  lint x;
  std::cin >> x;
  return x;
}

vector<lint> Fib{0, 1, 1};
lint fib(int k) {
  if (k < 0)
    return 0;
  if (k == 0)
    return 0;
  if (k < 3)
    return 1;
  if (Fib.size() <= k + 1) {
    Fib.push_back(fib(k - 1) + fib(k - 2) /* % mod */);
  }

  return Fib[k];
}

signed main() { cout << fib(in() + 1) << endl; }

Error: TLE

Fixed submission:

#include <stdio.h>

// int f[44];

int fib(int n) {
  if (n < 2)
    return 1;
  // if (f[n] == 0) f[n] =
  return fib(n - 1) + fib(n - 2);
  // return f[n];
}

int main() {
  int n;

  scanf("%d", &n);

  printf("%d\\n", fib(n));

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

//
// Created by 李青坪 on 2018/10/28.
//

#include <algorithm>
#include <cstdio>
#define MAXN 50
#define NIL -1
using namespace std;

int value[MAXN];

int fibonacci(int n) {
  if (n == 0 || n == 1) {
    value[n] = 1;
    return 1;
  }
  if (value[n] != NIL)
    return value[n];
  value[n] = fibonacci(n - 1) + fibonacci(n - 2);
  return value[n];
}

int main() {
  fill(value, value + MAXN, NIL);
  int n;
  scanf("%d", &n);
  printf("%d\\n", fibonacci(n));
}


Error: TLE

Fixed submission:

//
// Created by 李青坪 on 2018/10/28.
//

#include <algorithm>
#include <cstdio>
#define MAXN 44
#define NIL -1
using namespace std;

int value[MAXN];

int fibonacci(int n) {
  if (n == 0 || n == 1) {
    value[n] = 1;
    return 1;
  }
  if (value[n - 1] != NIL && value[n - 2] != NIL) {
    return value[n - 1] + value[n - 2];
  }
  if (value[n - 1] != NIL && value[n - 2] == NIL) {
    return value[n - 1] + fibonacci(n - 2);
  }
  if (value[n - 1] == NIL && value[n - 2] != NIL) {
    return fibonacci(n - 1) + value[n - 2];
  }
  return fibonacci(n - 1) + fibonacci(n - 2);
}

int main() {
  fill(value, value + MAXN, NIL);
  int n;
  scanf("%d", &n);
  printf("%d\\n", fibonacci(n));
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int fib[45];
  fib[0] = 1;
  fib[1] = 1;
  for (int i = 2; i < 45; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }

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

  printf("%d\\n", fib[n]);
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int fib(int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 1;
  return fib(n - 1) + fib(n - 2);
}

int main() {
  int n;
  scanf("%d", &n);
  printf("%d\\n", fib(n));
}
Problem p02233 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>

int fib(int n) {
  int i;
  int a[44];
  a[0] = a[1] = 1;
  for (i = 2; i <= n; i++) {
    a[i] = a[i - 1] + a[i - 2];
  }
  return a[n];
}

int main() {

  int x, n;
  scanf("%d", &n);
  x = fib(n);
  printf("%d\\n", x);

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>

int fib(int n) {
  int i;
  int a[25];
  a[0] = a[1] = 1;
  for (i = 2; i <= n; i++) {
    a[i] = a[i - 1] + a[i - 2];
  }
  return a[n];
}

int main() {

  int x, n;
  scanf("%d", &n);
  x = fib(n);
  printf("%d\\n", x);

  return 0;
}