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

#include <iostream>
#define MAX 44
using namespace std;

long long fib[MAX];

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

long long 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;
  // for(int n=0;n<=44;n++){
  cout << fib(n) << endl;
  //}
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 1e9
vector<int> memo;

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

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

  memo = vector<int>(n + 1, -INF);
  memo[0] = memo[1] = 1;

  cout << fib(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(void) {
  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 solution(int n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 1;
  int one = 1, two = 1, tmp;
  for (int i = 1; i < n; i++) {
    tmp = two;
    two = two + one;
    one = tmp;
  }
  return two;
}

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

Error: TLE

Fixed submission:

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

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

#include <iostream>

using namespace std;
int main() {
  int f[100];
  int n;
  cin >> n;
  f[0] = 1;
  f[1] = 1;
  for (int i = 0; i < n; i++) {
    f[i + 2] = f[i + 1] + f[i];
  }
  cout << f[n] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <set>
#include <string>
using namespace std;
int f(int n) {
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return 1;
  }
  return f(n - 1) + f(n - 2);
};

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

/*
 * ALDS1_10_A.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include <iostream>

using namespace std;

int F[44];

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

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

  F[0] = F[1] = 1;

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


Error: TLE

Fixed submission:

/*
 * ALDS1_10_A.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include <iostream>

using namespace std;

int F[44];

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

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

  F[0] = F[1] = 1;

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

#include <cstdio>
#include <iostream>

using namespace std;

int m[45];
void function(int n) {
  m[0] = 1;
  m[1] = 1;
  for (int i = 2; i <= n; i++) {
    m[i] = m[i - 1] + m[i - 2];
  }
}

int main() {
  int n;
  cin >> n;
  function(n);
  cout << m[n] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

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

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

#include <bits/stdc++.h>
using namespace std;
#define MAX 50
int fibonacci(int);
int F[MAX];

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAX 44
int fibonacci(int);
int F[MAX];

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

int fibonacci(int n) {
  if (n == 0 || n == 1) {
    return F[n] = 1;
  }
  return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
}
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) {
  /* ??????1 */
  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[1000];

int main() {
  int n;

  // 入力
  cin >> n;

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

  return 0;
}

int fib(int n) {
  if (n == 0 || 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) {
  int memo[1000];
  if (n == 0 || n == 1) {
    return 1;
  } else if (memo[n] != 0) {
    return memo[n];
  } else {
    return memo[n] = 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[1000];

int main() {
  int n;

  // 入力
  cin >> n;

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

  return 0;
}

int fib(int n) {

  if (n == 0 || 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) {
  int memo[1000] = {0};

  if (n == 0 || n == 1) {
    return memo[n] = 1;
  } else if (memo[n] != 0) {
    return memo[n];
  } else {
    return memo[n] = 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[1000];

int main() {
  int n;

  // 入力
  cin >> n;

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

  return 0;
}

int fib(int n) {

  if (n == 0 || 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: Time Limit Exceeded

#include <cstdio>

using namespace std;

int sum = 0, dp[50];

int fib(int n) {

  if (n == 0 || n == 1) {

    return dp[n] = 1;

  } else if (dp[n] != -1) {

    return dp[n];

  } else {

    return dp[n] = fib(n - 1) + fib(n - 2);
  }
}

int main() {

  int n;

  scanf("%d", &n);

  for (int i = 0; i < 50; i++)
    dp[i] = -1;

  int ans = fib(n);

  printf("%d\\n", ans);
}


Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

int sum = 0;

int fib(int n) {

  if (n >= 0) {

    if (n == 0 || n == 1) {

      return 1;

    } else {

      sum = fib(n - 1) + fib(n - 2);
    }

  } else
    return 0;

  return sum;
}

int main() {

  int n;

  scanf("%d", &n);

  int ans = fib(n);

  printf("%d\\n", ans);
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

long long fibodp(int n) {
  long long fibodp[200] = {0};
  fibodp[0] = 1;
  fibodp[1] = 1;
  for (int i = 2; i <= n; i++) {
    fibodp[i] = fibodp[i - 1] + fibodp[i - 2];
  }
  return fibodp[n];
}

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

#include <iostream>
using namespace std;

#define MAX 45

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

int main() {
  int C;

  cin >> C;

  // cout << fibonacci(C) << endl;

  int F[MAX];

  F[0] = 1;
  F[1] = 1;

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

  cout << F[C] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

int main() {
  int C;

  cin >> C;

  cout << fibonacci(C) << endl;

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

#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;

long long Fib(int n) {
  vector<long long> F(n + 1);
  int i;
  F[0] = 1;
  F[1] = 1;
  for (i = 2; i <= n; i++) {
    F[i] = F[i - 1] + F[i - 2];
  }
  return F[n];
}

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

  int n;
  cin >> n;

  cout << Fib(n) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;

long long Fib(int n) {
  vector<long long> F(n + 1);
  int i;
  F[0] = 1;
  F[1] = 1;
  for (i = 2; i <= n + 1; i++) {
    F[i] = F[i - 1] + F[i - 2];
  }
  return F[n];
}

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

  int n;
  cin >> n;

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

#include <iostream>
using namespace std;

#define MAX 50

int dp[MAX];

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

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

  cout << fib(n) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#define MAX 50

int dp[MAX];

int fib(int n) {
  if (n < 0)
    return 0;
  if (n == 0 || n == 1) {
    dp[n] = 1;
    return 1;
  }
  return dp[n] = 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

#define scanf_s scanf
#include <iostream>
using namespace std;
int F[46] = {0};
int fib(int n) {
  if (n >= 0) {
    if (n <= 1) {
      return F[n] = 1;
    }
    if (F[n] != 0) {
      return F[n];
    }
    return F[n] = fib(n - 1) + fib(n - 2);
  }
}
int main(void) {
  int n;
  scanf_s("%d", &n);
  printf("%d\\n", fib(n));
}

Error: TLE

Fixed submission:

#define scanf_s scanf
#include <iostream>
using namespace std;
int fib(int n) {
  if (n >= 0) {
    if (n <= 1)
      return 1;
    return fib(n - 1) + fib(n - 2);
  }
}
int main(void) {
  int n;
  scanf_s("%d", &n);
  printf("%d\\n", fib(n));
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

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

class Fibonacci {
private:
  int f[45];
  int len;

public:
  Fibonacci() {
    f[0] = f[1] = 1;
    len = 2;
  }
  int calc(int n);
};

int Fibonacci::calc(int n) {
  if (n < len)
    return f[n];
  f[n] = calc(n - 1) + calc(n - 2);
  len++;
  return f[n];
}

int main(void) {
  Fibonacci fib;
  int n;
  cin >> n;
  cout << fib.calc(n) << endl;
}

Error: TLE

Fixed submission:

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

int fib(int n);

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> fibo(n + 2);
  fibo[0] = 1;
  fibo[1] = 1;
  for (int i = 2; i < n + 2; i++) {
    fibo[i] = fibo[i - 1] + fibo[i - 2];
  }

  cout << fibo[n] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int fibo(int n) {
  if (n == 0 || n == 1)
    return 1;
  return fibo(n - 1) + fibo(n - 2);
}
int main() {
  int n;
  cin >> n;
  cout << fibo(n) << endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  int F[10000];
  cin >> n;

  F[0] = F[1] = 1;

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

  cout << F[n] << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int FibonacciNumber(int n) {

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

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

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

#include <iostream>

using namespace std;

unsigned long memo[50] = {};

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

  cin >> n;

  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: Runtime Error

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

void makeFibonacci(int fib[]) {
  fib[0] = 1;
  fib[1] = 1;
  for (int i = 2; i <= 44; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
}

int main() {

  int fib[45];
  makeFibonacci(fib);

  int n;
  scanf("%d", &n);
  printf("%d\\n", fib[n]);

  return 0;
}


Error: 255

Fixed submission:

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

void makeFibonacci(int fib[]) {
  fib[0] = 1;
  fib[1] = 1;
  for (int i = 2; i <= 44; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
}

int main() {

  int fib[45];
  makeFibonacci(fib);

  int n;
  scanf("%d", &n);
  printf("%d\\n", fib[n]);

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

#include <iostream>
using namespace std;

int F[100];
int main() {
  F[0] = 1;
  F[1] = 1;

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

  int N;
  cin >> N;
  cout << F[N] << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int Fibonacci(int N) {
  if (N == 0) {
    return 1;
  } else if (N == 1) {
    return 1;
  } else {
    return Fibonacci(N - 1) + Fibonacci(N - 2);
  }
}

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

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int M = 2;
int a[M][M], b[M][M], w[M][M];
int n;

void multiple_mat_ab_b() {
  int i, j, k;
  memset(w, 0, sizeof(w));
  for (i = 0; i < M; i++)
    for (j = 0; j < M; j++)
      for (k = 0; k < M; k++)
        w[i][j] += a[i][k] * b[k][j];

  for (i = 0; i < M; i++)
    for (j = 0; j < M; j++)
      b[i][j] = w[i][j];
}

void multiple_mat_aa_a() {
  int i, j, k;
  memset(w, 0, sizeof(w));
  for (i = 0; i < M; i++)
    for (j = 0; j < M; j++)
      for (k = 0; k < M; k++)
        w[i][j] += a[i][k] * a[k][j];

  for (i = 0; i < M; i++)
    for (j = 0; j < M; j++)
      a[i][j] = w[i][j];
}

void pow_mat_a(int k) {
  a[0][0] = a[0][1] = a[1][0] = 1;
  a[1][1] = 0;

  b[0][0] = b[1][1] = 1;
  b[0][1] = b[1][0] = 0;

  //?????´???a???k????????????
  for (int i = 0; i < k; i++)
    multiple_mat_ab_b();
}

int main() {
  scanf("%d ", &n);
  pow_mat_a(n);
  printf("%d\\n", b[1][0] + b[1][1]);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 44;
int n;
int dp[N + 1];

//???????£?
// recursive function(with/without memo)

int fib(int k) {
  if (dp[k])
    return dp[k];
  return fib(k - 1) + fib(k - 2);
}

int main() {
  memset(dp, 0, sizeof(dp));
  dp[0] = dp[1] = 1;
  scanf("%d ", &n);
  printf("%d\\n", fib(n));

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

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

int Fib(int n) {
  double phi = (1 + sqrt(5)) / 2;
  return floor(pow(phi, n) / sqrt(5) + 0.5);
}

int main() {
  int n;

  while (cin >> n) {
    cout << Fib(n + 1) << 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>
#include <vector>
using namespace std;

void fibonacci(int n) {
  vector<int> fib;

  fib.push_back(1);
  fib.push_back(1);

  if (n < 2) {
    cout << "1" << endl;
  } else if (n == 2) {
    fib.push_back(fib.at(0) + fib.at(1));
    cout << fib.back() << endl;
  } else {
    for (int i = 2; i < n + 1; i++) {
      fib.push_back(fib.at(i - 2) + fib.at(i - 1));
    }
    cout << fib.back() << endl;
  }
}

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

  fn = fibonacci(n);

  cout << fn << endl;

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

// ALDS1_10_A.cpp
// Dynamic Programming - Fibonacci Number

#include <iostream>
using namespace std;

int fib(int n) {
  if (n == 0 || n == 1)
    return 1;
  int pre = 1;
  int curr = 1;
  int next = 1;
  while (n-- > 1) {
    next = pre + curr;
    pre = curr;
    curr = next;
  }
  return next;
}

int main() {
  int n;
  cin >> n;
  int res = fib(n);
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

// ALDS1_10_A.cpp
// Dynamic Programming - Fibonacci Number

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

#include <cstdio>
#define REP(I, n) for (int i = 2; i <= n; i++)
using namespace std;
int main() {
  int n;
  int F[45] = {0};
  scanf("%d", &n);
  F[0] = F[1] = 1;
  REP(i, n) F[i] = F[i - 1] + F[i - 2];
  printf("%d\\n", F[n]);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
int F[45] = {0};
int FIB(int u) {
  if (u == 0 || u == 1) {
    F[u] = 1;
    return F[u];
  } else {
    F[u] = FIB(u - 1) + FIB(u - 2);
    return F[u];
  }
}
int main() {
  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 num;

int fib(int n, int array[]) {
  array[0] = 1;
  array[1] = 1;
  for (int i = 2; i <= n; i++) {
    array[i] = array[i - 1] + array[i - 2];
  }
  cout << array[n] << endl;
}
int main(void) {

  cin >> num;
  int array[num] = {};
  fib(num, array);
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int num;

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define erep(i, a, b) for (int i = a; i <= (int)(b); i++)
#define per(i, a, b) for (int i = (b)-1; i > (a); i--)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; i--)
#define pb push_back
#define mp make_pair
#define INF (1 << 30) - 1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int n, dp[1000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  dp[0] = dp[1] = 1;
  erep(i, 2, n) { dp[i] = dp[i - 1] + dp[i - 2]; }
  cout << dp[n] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define erep(i, a, b) for (int i = a; i <= (int)(b); i++)
#define per(i, a, b) for (int i = (b)-1; i > (a); i--)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; i--)
#define pb push_back
#define mp make_pair
#define INF (1 << 30) - 1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int n;
int fib(int x) {
  if (x == 0)
    return 1;
  if (x == 1)
    return 1;
  return fib(x - 1) + fib(x - 2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cout << fib(n) << endl;
  return 0;
}
Problem p02233 (C++) — buggy submission, verdict: Time Limit Exceeded

// input: aldsalds1_10_a.in
#include <iostream>
#define MAX_N 45
#define NIL -1
using namespace std;

int dp[MAX_N];

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

  if (dp[n] != NIL)
    return dp[n];

  int v = fib(n - 1) + fib(n - 2);
  dp[n] = v;

  return v;
}

int main() {
  for (int i = 0; i < MAX_N; i++)
    dp[i] = NIL;

  int x;
  cin >> x;

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

Error: TLE

Fixed submission:

// input: aldsalds1_10_a.in
#include <iostream>
#define MAX_N 45
#define NIL -1
using namespace std;

int dp[MAX_N];

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

  if (dp[n] != NIL)
    return dp[n];

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

int main() {
  for (int i = 0; i < MAX_N; i++)
    dp[i] = NIL;

  int x;
  cin >> x;

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