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

#include <iostream>
#include <vector>
#define NIL -1
using namespace std;

int fib(vector<int> &F, int n) {
  if (F[n] != NIL)
    return F[n];
  return F[n] = fib(F, n - 1) + fib(F, n - 2);
}

int main() {
  int n;
  cin >> n;
  vector<int> F(n + 1, NIL);
  F[0] = F[1] = 1;
  cout << fib(F, n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#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;
  cin >> n;
  cout << fib(n) << endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main(void) {

  int n, fib[45];
  fib[0] = fib[1] = 1;

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

  while (cin >> n)
    cout << fib[n] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

int main(void) {

  int n;

  while (cin >> n)
    cout << fib(n) << endl;

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

#include <cstdio>

int fibo(int n, int *dp) {
  if (n == 0 || n == 1)
    return 1;
  if (0 < dp[n])
    return dp[n];
  return dp[n] = fibo(n - 1, dp) + fibo(n - 2, dp);
}

int main() {
  int n;
  int dp[50];
  for (int i = 0; i < 50; i++)
    dp[i] = -1;
  scanf("%d", &n);
  printf("%d\\n", fibo(n, dp));
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int fibo(int n, int *dp) {
  if (n == 0 || n == 1)
    return 1;
  if (0 < dp[n])
    return dp[n];
  return fibo(n - 1, dp) + fibo(n - 2, dp);
}

int main() {
  int n;
  int dp[50];
  for (int i = 0; i < 50; i++)
    dp[i] = -1;
  scanf("%d", &n);
  printf("%d\\n", fibo(n, dp));
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

long *memo;
long fib(long n) {
  if (n < 2)
    return 1;
  return memo[n] != -1 ? memo[n] : (memo[n] = fib(n - 1) + fib(n - 2));
}

int main() {
  memo = new long[64];
  for (int i = 0; i < 64; i++) {
    memo[i] = -1;
  }

  long n;
  cin >> n;
  cout << fib(n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

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

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

int main() {
  int n;
  cin >> n;

  vector<int> fib(n + 5);

  fib[0] = 1;
  fib[1] = 1;

  for (int i = 2; i <= n; i++)
    fib[i] = fib[i - 2] + fib[i - 1];

  cout << fib[n] << endl;
  ;

  return 0;
}


Error: TLE

Fixed submission:

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

  cout << fib(n) << endl;
  ;

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

#include <iostream>

using namespace std;

int ans[45] = {};

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

int main() {
  int i = 0;
  cin >> i;
  cout << fib(i) << 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 i = 0;
  cin >> i;
  cout << fib(i) << endl;
}
Problem p02233 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
#define eol '\\n'
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> list(n + 1, 0);
  list[0] = list[1] = 1;

  for (int i = 2; i <= n; i++) {
    list[i] = list[i - 1] + list[i - 2];
  }

  cout << list[n] << eol;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
#define eol '\\n'
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> list(n, 0);
  list[0] = list[1] = 1;

  for (int i = 2; i <= n; i++) {
    list[i] = list[i - 1] + list[i - 2];
  }

  cout << list[n] << eol;

  return 0;
}
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;
}

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) {
  /* ??????1 */
  if (n <= 1)
    return 1;
  return fib(n - 1) + fib(n - 2);
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int f[45];
int fib(int n) {
  if (n == 1 || n == 0)
    return 1;
  if (f[n] != 0)
    return f[n];
  else
    return f[n] = fib(n - 1) + fib(n - 2);
}
int main() {
  int n;
  cin >> n;
  cout << fib(n) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int f[45];
int fib(int n) {
  if (n == 1 || n == 0)
    return 1;
  if (f[n] != 0)
    return f[n];
  else
    return fib(n - 1) + fib(n - 2);
}
int main() {
  int n;
  cin >> n;
  cout << fib(n) << endl;

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

#include <iostream>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

ll dp[50];

ll fib(int n) {
  if (n < 3)
    return n;
  if (dp[n] == 0)
    dp[n] = fib(n - 1) + fib(n - 2);
  return dp[n];
}

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


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

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

int main() {
  int n;
  cin >> n;
  cout << fib(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 || n == 1) {
    return 1;
  } else {
    return fib(n - 1) + fib(n - 2);
  }
}
Problem p02233 (C++) — buggy submission, verdict: Runtime Error

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

void fnInput(vector<int> &rvnFibDP) {
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnFibDP.resize(nMaxSiz + 1, 0);

  if (nMaxSiz >= 1)
    rvnFibDP[0] = rvnFibDP[1] = 1;
  else
    rvnFibDP[0] = 1;
}

int fnFibNumber(vector<int> &rvnFibDP, int nNo) {
  if (rvnFibDP[nNo])
    return rvnFibDP[nNo];

  return rvnFibDP[nNo] =
             fnFibNumber(rvnFibDP, nNo - 1) + fnFibNumber(rvnFibDP, nNo - 2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnFibDP;

  fnInput(vnFibDP);
  cout << fnFibNumber(vnFibDP, vnFibDP.size() - 1) << endl;
  return 0;
}

Error: 0

Fixed submission:

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

void fnInput(vector<int> &rvnFibDP) {
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnFibDP.resize(nMaxSiz + 1, 0);

  if (nMaxSiz >= 2)
    rvnFibDP[0] = rvnFibDP[1] = 1;
  else if (nMaxSiz = 1)
    rvnFibDP[0] = 1;
  else
    ;
}

int fnFibNumber(vector<int> &rvnFibDP, int nNo) {
  if (rvnFibDP[nNo])
    return rvnFibDP[nNo];

  return rvnFibDP[nNo] =
             fnFibNumber(rvnFibDP, nNo - 1) + fnFibNumber(rvnFibDP, nNo - 2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnFibDP;

  fnInput(vnFibDP);
  cout << fnFibNumber(vnFibDP, vnFibDP.size() - 1) << endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

long long int Fibo(long long int n) {
  if (n == 0 || n == 1)
    return 1;
  if (n == 44)
    return 1134903170;
  return Fibo(n - 1) + Fibo(n - 2);
}
int main() {
  long long int n;
  std::cin >> n;
  std::cout << Fibo(n) << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

long long int Fibo(long long int n) {
  if (n == 0 || n == 1)
    return 1;
  return Fibo(n - 1) + Fibo(n - 2);
}
int main() {
  long long int n;
  std::cin >> n;
  std::cout << Fibo(n) << std::endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

long fivo(long req) {
  long dp[100001];
  dp[0] = 0;
  dp[1] = 1;

  int i;
  for (i = 2; i < req; i++) {
    dp[i] = dp[i - 1] + dp[i - 2];
    //       cout <<dp[i]<<" "<<"="<<dp[i-1]<<"+"<<dp[i-2]<<endl;
  }
  dp[req] = dp[req - 1] + dp[req - 2];

  return dp[req];
}

int main() {
  long n;
  int req;

  cin >> req;
  n = fivo(req + 1);
  //  for(n=1;n<=20;n++){
  // cout<<fivo(n)<<endl;
  // }
  cout << n << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

long fivo(long a) {
  if (a == 1 or a == 2)
    return 1L;

  else

    return fivo(a - 1) + fivo(a - 2);
}

int main() {
  long n, req;

  cin >> req;
  n = fivo(req + 1);
  //  for(n=1;n<=20;n++){
  // cout<<fivo(n)<<endl;
  // }
  cout << n << endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int n;
int F[45];
int fibo(int i) {
  if (F[i]) {
    return F[i];
  }
  F[i] = fibo(i - 1) + fibo(i - 2);
  return F[i];
}

int main() {
  cin >> n;
  F[0] = F[1] = 1;
  cout << fibo(n) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n;
int F[45];
int fibo(int i) {
  if (F[i]) {
    return F[i];
  }
  return fibo(i - 1) + fibo(i - 2);
}

int main() {
  cin >> n;
  F[0] = F[1] = 1;
  cout << fibo(n) << endl;

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

#include <cstdio>

int dp[44];
bool dpf[44] = {false};

int fib(int n) {
  if (n == 0 || n == 1)
    return dp[n] = 1;
  if (dpf[n] == true)
    return dp[n];
  dpf[n] = true;
  return dp[n] = fib(n - 1) + fib(n - 2);
}

int main() {
  int n;
  scanf("%d", &n);
  printf("%d\\n", fib(n));
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

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);
  printf("%d\\n", fib(n));
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int F[50];
int fib(int i) {
  if (i == 0 || i == 1)
    return 1;

  if (F[i] != -1)
    return F[i];

  return F[i] = fib(i - 1) + fib(i - 2);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 50; i++)
    F[i] = -1;
  cout << fib(n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int fib(int i) {
  if (i == 0 || i == 1)
    return 1;
  else
    return fib(i - 1) + fib(i - 2);
}

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

#include <iostream>

using namespace std;

int fibdp[50];

int fib(int n) {
  if (n == 1 || n == 0) {
    return 1;
  }
  if (fibdp[n] != 0) {
    return fibdp[n];
  }
  return fibdp[n] = fib(n - 1) + fib(n - 2);
}
int main() {
  int n;

  cin >> n;

  cout << fib(n) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int fib(int n) {
  if (n == 1 || n == 0) {
    return 1;
  } else {
    return fib(n - 1) + fib(n - 2);
  }
}
int main() {
  int n;

  cin >> n;

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

#include <iostream>

using namespace std;

int A[128];
int fib(int n) {
  A[0] = 1;
  A[1] = 2;
  for (int i = 2; i < 44; ++i) {
    A[i] = A[i - 1];
    if (i > 1)
      A[i] += A[i - 2];
  }
  return A[n - 1];
}
int main() {
  int n;
  cin >> n;
  cout << fib(n) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

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

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int F[50];
  F[0] = 1;
  F[1] = 1;

  for (int i = 2; i <= n; i++) {
    F[i] = F[i - 1] + F[i - 2];
  }

  cout << F[n] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int F[50];
  F[0] = F[1] = 1;

  for (int i = 2; i <= n; n++) {
    F[i] = F[i - 1] + F[i - 2];
  }

  cout << F[n] << endl;

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

#include <bits/stdc++.h>

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

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int dp[44];

ll f(int n) {

  if (dp[n])
    return dp[n];
  else
    dp[n] = f(n - 1) + f(n - 2);

  return dp[n];
}

int main() {

  int x;
  REP(i, 44) { dp[i] = 0; }

  dp[0] = 1;
  dp[1] = 1;

  cin >> x;
  cout << f(x) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

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

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

ll f(int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 1;

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

int main() {

  int x;

  cin >> x;
  cout << f(x) << endl;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

int memo[45];

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

int fib1(int n) { return (int)(pow((1 + sqrt(5)) / 2, n) / sqrt(5) + 0.5); }

int main() {
  int n;
  cin >> n;
  fill_n(memo, 45, 0);
  cout << fib(n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

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;
  cout << fib(n) << endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int lld;

const lld mod = 1e9 + 7;
const lld INF = 1e9;
// const lld MAXN = 1e9;

int fib[45] = {0};

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int lld;

const lld mod = 1e9 + 7;
const lld INF = 1e9;
// const lld MAXN = 1e9;

int fib[45];

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

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

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int f(const int);

int main() {
  int N;
  int num = 1, old[2] = {1, 1};
  cin >> N;
  for (int i = 1; i < N; i++) {
    num = old[0] + old[1];
    old[0] = old[1];
    old[1] = num;
  }
  cout << num << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int f(const int);

int main() {
  int N;
  cin >> N;
  cout << f(N) << endl;
}
int f(const int d) {
  if (d < 2)
    return 1;
  return f(d - 1) + f(d - 2);
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

vector<int> a(100);

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

int main(void) {
  int n;
  cin >> n;

  cout << fibonacci(n) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int fibonacci(int n) {
  if (n == 0 || n == 1) {
    return 1;
  }
  return fibonacci(n - 2) + fibonacci(n - 1);
}

int main(void) {
  int n;
  cin >> n;

  cout << fibonacci(n) << endl;

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

#include <iostream>
using namespace std;

int main() {
  int x = 1, y = 1, n, value = 0;
  cin >> n;

  if (n == 0 || n == 1)
    value = 1;
  else {
    while (n > 1) {
      value = x + y;
      x = y;
      y = value;
      n--;
    }
  }
  cout << value << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int Fibonacci(int n) {
  if (n == 0 || n == 1)
    return 1;
  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>

using namespace std;

typedef unsigned long long ull;

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

typedef unsigned long long ull;

auto fib(ull const n) -> ull {
  return (n == 0 || n == 1) ? 1 : fib(n - 2) + fib(n - 1);
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

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

int fib(int n) {

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

  int ans = 0;
  int fib_1, fib_2;
  fib_1 = 1;
  fib_2 = 1;

  for (int i = 2; i <= n; i++) {
    ans = fib_1 + fib_2;
    fib_2 = fib_1;
    fib_1 = ans;
  }

  return ans;
}

int main(int argc, const char *argv[]) {

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

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

  return 0;
}

Error: TLE

Fixed submission:

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

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

int fib(int n) {
  if (n == 0 || n == 1) {
    return 1;
  }

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

int main(int argc, const char *argv[]) {

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

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

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

#include <iostream>
using namespace std;

int F[44];

int fib(int n) {
  if (n == 0 || n == 1) {
    return F[n] = 1;
  }
  if (F[n] != -1) {
    return F[n];
  }
  return F[n] = fib(n - 1) + fib(n - 2);
}

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

  return 0;
}

Error: TLE

Fixed submission:

#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;

  cout << fib(n) << endl;

  return 0;
}