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

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

int dp[4001][4001];
int ans = 0;

int main() {
  while (true) {
    string s, t;
    cin >> s;
    if (!s.size())
      break;
    cin >> t;
    ans = 0;
    memset(dp, 0, sizeof dp);

    for (int i = 0; i < s.size(); i++)
      for (int j = 0; j < t.size(); j++)
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          ans = max(ans, dp[i + 1][j + 1]);
        }

    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int dp[4001][4001];
string s, t;
int ans = 0;

int main() {
  while (true) {
    cin >> s;
    if (!s.size())
      break;
    cin >> t;
    ans = 0;
    memset(dp, 0, sizeof dp);

    for (int i = 0; i < s.size(); i++)
      for (int j = 0; j < t.size(); j++)
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          ans = max(ans, dp[i + 1][j + 1]);
        }

    cout << ans << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int dp[4005][4005];

int main() {
  string s;
  while (cin >> s) {
    string sa;
    cin >> sa;
    for (int i = 0; i < 4003; i++)
      for (int j = 0; j < 4003; j++)
        dp[i][j] = 0;
    s.push_back('@');
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < sa.size(); j++) {
        int a = s.size();

        if (s[i] == sa[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          ans = max(ans, dp[i + 1][j + 1]);
        } else {
          dp[i + 1][j + 1] = 0;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int dp[4005][4005];

int main() {
  string s;
  while (cin >> s) {
    string sa;
    cin >> sa;
    for (int i = 0; i < 4003; i++)
      for (int j = 0; j < 4003; j++)
        dp[i][j] = 0;
    s.push_back('@');
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < sa.size(); j++) {
        int a = s.size();
        int I = min(a - 1, i + j);
        if (s[I] == sa[j]) {
          dp[I][j + 1] = dp[I - 1][j] + 1;
          ans = max(ans, dp[I][j + 1]);
        } else
          dp[I][j + 1] = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    // vector<vector<int> > dp(s1.size(), vector<int>(s2.size(), 0));
    vector<int> dp[2];
    dp[0].resize(s2.size());
    dp[1].resize(s2.size());
    fill(dp[0].begin(), dp[0].end(), 0);
    fill(dp[1].begin(), dp[1].end(), 0);

    int ans = 0;
    int l1 = s1.size();
    int l2 = s2.size();
    for (int i = 0; i < l1; ++i) {
      int curr = i & 1;
      int prev = 1 - curr;
      for (int j = 0; j < l2; ++j) {
        if (s1[i] == s2[j]) {
          if (i > 0 && j > 0)
            dp[curr][j] = dp[prev][j - 1] + 1;
          else
            dp[curr][j] = 1;
        } else
          dp[curr][j] = 0;
        if (dp[curr][j] > ans)
          ans = dp[curr][j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    vector<vector<int>> dp(s1.size(), vector<int>(s2.size(), 0));

    int ans = 0;
    int l1 = s1.size();
    int l2 = s2.size();
    for (int i = 0; i < l1; ++i) {
      for (int j = 0; j < l2; ++j) {
        if (s1[i] == s2[j]) {
          if (i > 0 && j > 0)
            dp[i][j] = dp[i - 1][j - 1] + 1;
          else
            dp[i][j] = 1;
        }
        if (dp[i][j] > ans)
          ans = dp[i][j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int N = 4001;
int dp[N][N];

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

  string s, t;
  while (1) {
    cin >> s;
    if (cin.eof() || s == "0") {
      break;
    }
    cin >> t;

    for (size_t i = 0; i < s.size(); ++i) {
      for (size_t j = 0; j < t.size(); ++j) {
        dp[i][j] = 0;
      }
    }

    int ans = 0;
    for (size_t i = 0; i < s.size(); ++i) {
      for (size_t j = 0; j < t.size(); ++j) {
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          ans = max(ans, dp[i + 1][j + 1]);
        } else
          dp[i + 1][j + 1] = 0;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int N = 4000;
int dp[N][N];

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

  string s, t;
  while (1) {
    cin >> s;
    if (cin.eof() || s == "0") {
      break;
    }
    cin >> t;

    for (size_t i = 0; i < s.size(); ++i) {
      for (size_t j = 0; j < t.size(); ++j) {
        dp[i][j] = 0;
      }
    }

    int ans = 0;
    for (size_t i = 0; i < s.size(); ++i) {
      for (size_t j = 0; j < t.size(); ++j) {
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          ans = max(ans, dp[i + 1][j + 1]);
        } else
          dp[i + 1][j + 1] = 0;
      }
    }

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

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

using namespace std;

int main() {
  string S, T;

  while (cin >> S >> T) {
    vector<vector<short>> dp(T.size() + 1, vector<short>(S.size() + 1, 0));

    for (int i = 0; i <= S.size(); i++) {
      dp[0][i] = 0;
    }
    for (int i = 0; i <= T.size(); i++) {
      dp[i][0] = 0;
    }

    int ret = 0;

    for (int i = 1; i <= T.size(); i++) {
      for (int j = 1; j <= S.size(); j++) {
        if (T[i - 1] == S[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else {
          dp[i][j] = 0;
        }

        ret = max(ret, (int)(dp[i][j]));
      }
    }

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

  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

int main() {
  string S, T;

  while (cin >> S >> T) {
    vector<vector<int>> dp(T.size() + 1, vector<int>(S.size() + 1, 0));

    for (int i = 0; i <= S.size(); i++) {
      dp[0][i] = 0;
    }
    for (int i = 0; i <= T.size(); i++) {
      dp[i][0] = 0;
    }

    for (int i = 1; i <= T.size(); i++) {
      for (int j = 1; j <= S.size(); j++) {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

        if (T[i - 1] == S[j - 1]) {
          dp[i][j]++;
        }
      }
    }

    printf("%d\\n", dp[T.size()][S.size()]);
  }

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

string str[2];
short dp[4001][4001];

void solve() {

  short ans = 0;

  if (str[0].length() > str[1].length()) {
    swap(str[0], str[1]);
  }
  for (short i = 0; i < 4001; i++) {
    for (short j = 0; j < 4001; j++)
      dp[j][i] = 0;
  }
  for (short i = 0; i < str[0].length(); i++) {
    for (short j = 0; j < str[1].length(); j++) {
      if (str[0][i] == str[1][j]) {
        dp[j + 1][i + 1] += (dp[j][i] + 1);
        ans = max(ans, dp[j + 1][i + 1]);
      }
    }
  }

  /*
  // dp表 確認(日本語)
  // dp-table checking(English)

          cout << " ";
          for(short i = 0; i < str[0].length(); i++)
                  cout << "  " << str[0][i];
          cout << endl;

          for(short i = 0; i < str[1].length(); i++){
                  cout << str[1][i];
                  for(short j = 0; j < str[0].length(); j++)
                          prshortf("%3d", dp[i][j]);
                  cout << endl;
          }
  */
  cout << ans << endl;
}

int main(void) {
  while (cin >> str[0] >> str[1], !cin.eof()) {
    solve();
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

string str[2];
int dp[4001][4001];

void solve() {

  int ans = 0;

  if (str[0].length() > str[1].length()) {
    swap(str[0], str[1]);
  }
  for (int i = 0; i < 4001; i++) {
    for (int j = 0; j < 4001; j++)
      dp[j][i] = 0;
  }
  for (int i = 0; i < str[0].length(); i++) {
    for (int j = 0; j < str[1].length(); j++) {
      if (str[0][i] == str[1][j]) {
        dp[j + 1][i + 1] += (dp[j][i] + 1);
        ans = max(ans, dp[j + 1][i + 1]);
      }
    }
  }

  /*
  // dp表 確認(日本語)
  // dp-table checking(English)

          cout << " ";
          for(int i = 0; i < str[0].length(); i++)
                  cout << "  " << str[0][i];
          cout << endl;

          for(int i = 0; i < str[1].length(); i++){
                  cout << str[1][i];
                  for(int j = 0; j < str[0].length(); j++)
                          printf("%3d", dp[i][j]);
                  cout << endl;
          }
  */
  cout << ans << endl;
}

int main(void) {
  while (cin >> str[0] >> str[1], !cin.eof()) {
    solve();
  }

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

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

short mat[4000][4000];

int lcs(string s, string t) {
  int z = 0;
  for (int i = 0; i < s.length(); ++i) {
    for (int j = 0; j < t.length(); ++j) {
      if (s.at(i) == t.at(j)) {
        if (i == 0 || j == 0)
          mat[i][j] = 1;
        else {
          mat[i][j] = mat[i - 1][j - 1] + 1;
        }
        z = max(z, (int)mat[i][j]);
      }
    }
  }
  return z;
}

int main() {
  string s, t;
  while (cin >> s) {
    cin >> t;
    memset(mat, 0, sizeof(mat));
    cout << lcs(s, t) << endl;
  }
}

Error: MLE

Fixed submission:

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

int mat[4000][4000];

int lcs(string s, string t) {
  int z = 0;
  for (int i = 0; i < s.length(); ++i) {
    for (int j = 0; j < t.length(); ++j) {
      if (s.at(i) == t.at(j)) {
        if (i == 0 || j == 0)
          mat[i][j] = 1;
        else {
          mat[i][j] = mat[i - 1][j - 1] + 1;
        }
        z = max(z, mat[i][j]);
      }
    }
  }
  return z;
}

int main() {
  string s, t;
  while (cin >> s) {
    cin >> t;
    memset(mat, 0, sizeof(mat));
    cout << lcs(s, t) << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int dp[4010][4010], maxn;
string S, T;

int main() {
  while (cin >> S >> T) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < S.size(); i++) {
      for (int j = 0; j < T.size(); j++) {
        if (S[i] == T[j]) {
          dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]);
        }
      }
    }
    maxn = 0;
    for (int i = 0; i <= S.size(); i++) {
      for (int j = 0; j <= T.size(); j++) {
        maxn = max(maxn, dp[i][j]);
      }
    }
    cout << maxn << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string S, T;
int v, _max;
int main() {
  while (v < 10) {
    v++;
    _max = 0;
    cin >> S >> T;
    for (int i = 1; i <= min(T.size(), S.size()); i++) {
      for (int j = 0; j <= S.size() - i; j++) {
        for (int k = 0; k <= T.size() - i; k++) {
          if (S.substr(j, i) == T.substr(k, i)) {
            _max = i;
          }
        }
      }
    }
    cout << _max << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

short dp[4000][4000];
char s[4004], t[4004];

int main() {
  while (cin >> s >> t) {
    for (int j = 0; j < 4000; ++j) {
      fill(dp[j], dp[j] + 4000, 0);
    }

    int sLen = strlen(s);
    int tLen = strlen(t);

    short ret = 0;

    for (int j = 0; j < sLen; ++j) {
      for (int k = 0; k < tLen; ++k) {
        if (s[j] != t[k]) {
          dp[j][k] = 0;
        } else if (j == 0 || k == 0) {
          dp[j][k] = 1;
        } else {
          dp[j][k] = dp[j - 1][k - 1] + 1;
        }

        ret = max(ret, dp[j][k]);
      }
    }

    cout << ret << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int dp[4000][4000];
char s[4001], t[4001];

int main() {
  while (cin >> s >> t) {
    for (int j = 0; j < 4000; ++j) {
      fill(dp[j], dp[j] + 4000, 0);
    }

    int sLen = strlen(s);
    int tLen = strlen(t);

    int ret = 0;

    for (int j = 0; j < sLen; ++j) {
      for (int k = 0; k < tLen; ++k) {
        if (s[j] != t[k]) {
          dp[j][k] = 0;
        } else if (j == 0 || k == 0) {
          dp[j][k] = 1;
        } else {
          dp[j][k] = dp[j - 1][k - 1] + 1;
        }

        ret = max(ret, dp[j][k]);
      }
    }

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

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

int dp[4001][4001];
char s1[4001], s2[4001];

int main() {
  while (scanf("%s", s1) != EOF) {
    scanf("%s", s2);
    int ans = 0;
    for (int i = 0; s1[i] != 0; i++) {
      for (int j = 0; s2[j] != 0; j++) {
        dp[i][j] = 0;
        if (s1[i] == s2[j]) {
          if (i == 0 || j == 0)
            dp[i][j] = 1;
          else
            dp[i][j] = dp[i - 1][j - 1] + 1;
        }
        ans = max(ans, dp[i][j]);
      }
    }
    printf("%d\\n", ans);
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;

char d[2][4005];
int dp[4001][4001];

int main() {
  while (scanf("%s%s", d[0], d[1])) {
    for (int i = 0; i <= 4000; i++)
      for (int j = 0; j <= 4000; j++)
        dp[i][j] = 0;
    int i, j;
    int res = 0;
    for (i = 0; d[0][i] != 0; i++) {
      for (j = 0; d[1][j] != 0; j++) {
        if (d[0][i] == d[1][j])
          dp[i + 1][j + 1] = dp[i][j] + 1;
        res = max(res, dp[i + 1][j + 1]);
      }
    }
    printf("%d\\n", res);
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>

int main(void) {
  char ra[4005] = {0};
  char rb[4005] = {0};
  while (scanf("%s%s", ra, rb) != EOF) {
    int alen = strlen(ra);
    int blen = strlen(rb);
    // printf("%d\\n%d\\n",alen,blen);
    int i = 0;
    int j = 0;
    int k = 0;
    int h = 0;
    int km = 0;
    int ans = 0;
    /*raとrbをiだけずらす。*/
    for (i = -blen; i < alen; i++) {
      /*k=(alen-i<blen)?alen-i:blen;
        h=(i<0)?-i:0;*/
      h = 0;
      k = alen;
      km = 0;
      for (j = h; j < k; j++) {
        if (j >= 0 && i + j >= 0) {
          if (j >= alen || j + i >= blen) {
            ans = (ans < km) ? km : ans;
            km = 0;
            break;
          }
          if (ra[j] == rb[i + j]) {
            km++;
          } else {
            ans = (ans < km) ? km : ans;
            km = 0;
          }
        }
      }
      ans = (ans < km) ? km : ans;
      km = 0;
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

int main(void) {
  char ra[4005] = {0};
  char rb[4005] = {0};
  while (scanf("%s%s", ra, rb) != EOF) {
    int alen = strlen(ra);
    int blen = strlen(rb);
    // printf("%d\\n%d\\n",alen,blen);
    int i = 0;
    int j = 0;
    int k = 0;
    int km = 0;
    int ans = 0;
    for (i = 0; i < alen; i++) {
      for (j = 0; j < blen; j++) {
        if (ra[i] == rb[j]) {
          k = 0;
          km = -1;
          while (k < blen - j && k < alen - i && ra[i + k] == rb[j + k]) {
            k++;
            if (km == -1 && ra[i] == rb[j + k])
              km = k;
          }
          ans = (ans < k) ? k : ans;
          if (km != -1) {
            j += km - 1;
          } else {
            j += k - 1;
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
#define SQR(a) ((a) * (a))
using namespace std;
typedef long long int ll;
typedef pair<int, int> pr;
typedef pair<pr, ll> ppr;
typedef vector<pr> vpr;
const int INF = 1 << 30;
int DP[4001][4001] = {};
int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    REP(i, 4001)
    REP(j, 4001)
    DP[i][j] = 0;
    int maxim = 0;
    REP(i, s1.size())
    REP(j, s2.size()) {
      if (s1[i] == s2[j])
        DP[i + 1][j + 1] = DP[i][j] + 1;
      maxim = max(maxim, DP[i + 1][j + 1]);
    }
    cout << maxim << endl;
  }
  // your code goes here
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
#define SQR(a) ((a) * (a))
using namespace std;
typedef long long int ll;
typedef pair<int, int> pr;
typedef pair<pr, ll> ppr;
typedef vector<pr> vpr;
const int INF = 1 << 30;
int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    int maxim = 0;
    REP(i, s1.size())
    REP(j, s2.size())
    REP(k, INF) {
      if (i + k < s1.size() && j + k < s2.size() && s1[i + k] == s2[j + k])
        continue;
      maxim = max(maxim, k);
      break;
    }
    cout << maxim << endl;
  }
  // your code goes here
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  b += MOD;
  a += b;
  a %= MOD;
}

int n, m, memo[4444][4444];
bool done[4444][4444];
char s[4444], t[4444];

int dp(int i, int j) {
  if (done[i][j]) {
    return memo[i][j];
  }
  done[i][j] = true;
  if (i == n || j == m) {
    memo[i][j] = 0;
  } else if (s[i] != t[j]) {
    memo[i][j] = 0;
  } else {
    memo[i][j] = dp(i + 1, j + 1) + 1;
  }
  return memo[i][j];
}

int main(void) {
  int i, j, ans;
  while (scanf(" %s ", s) != EOF) {
    fill(done[0], done[4444], false);
    ans = 0;
    scanf(" %s ", t);
    n = strlen(s);
    m = strlen(t);
    for (i = 0; i < n; ++i) {
      for (j = 0; j < m; ++j) {
        if (!done[i][j]) {
          ans = max(ans, dp(i, j));
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  b += MOD;
  a += b;
  a %= MOD;
}

int n, m, memo[4444][4444];
bool done[4444][4444];
char s[4444], t[4444];

int dp(int i, int j) {
  if (done[i][j]) {
    return memo[i][j];
  }
  done[i][j] = true;
  if (i == n || j == m) {
    memo[i][j] = 0;
  } else if (s[i] != t[j]) {
    memo[i][j] = 0;
  } else {
    memo[i][j] = dp(i + 1, j + 1) + 1;
  }
  return memo[i][j];
}

int main(void) {
  int i, j, ans;
  while (scanf("%s", s) != EOF) {
    fill(done[0], done[4444], false);
    ans = 0;
    scanf("%s", t);
    n = strlen(s);
    m = strlen(t);
    for (i = 0; i < n; ++i) {
      for (j = 0; j < m; ++j) {
        ans = max(ans, dp(i, j));
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#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--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  while (true) {
    string s1, s2;
    cin >> s1;
    if (cin.eof())
      break;
    cin >> s2;
    int ans = 0;
    int h = s1.size() + 1;
    int l = 0;
    int m = (h + l) / 2;
    REP(i, 20) {
      bool flg = false;
      set<string> ss;
      REP(i, s1.size() - m + 1) { ss.insert(s1.substr(i, m)); }

      REP(i, s2.size() - m + 1) {
        if (ss.find(s2.substr(i, m)) != ss.end()) {
          flg = true;
        }
      }
      if (flg) {
        l = m;
        //		printf("m = %d\\n",m);
      } else {
        h = m;
      }
      m = (h + l) / 2;
    }
    cout << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#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--)

#define PB push_back
#define INF (1 << 29)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0};

typedef long long int ll;

using namespace std;

int main() {
  while (true) {
    string s1, s2;
    cin >> s1;
    if (cin.eof())
      break;
    cin >> s2;
    int ans = 0;
    REP(i, s1.size()) {
      char h = s1[i];
      REP(j, s2.size()) {
        if (s2[j] == h) {
          int temp = 0;
          FOR(k, j, s2.size()) {
            if (s1[i + k - j] == s2[k]) {
              temp++;
            } else {
              j = k - 1;
              break;
            }
          }
          ans = max(ans, temp);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}