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

#include <bits/stdc++.h>
using namespace std;
int ans, s1, s2;
int solve(int tt, int pp);
string text, patn;

int main() {

  while (cin >> text) {
    cin >> patn;
    s1 = text.size();
    s2 = 0;
    ans = 0;
    while (s1 != 0 || s2 <= (int)patn.size()) {
      if (s1 != 0)
        s1--;
      else
        s2++;
      ans = max(ans, solve(s1, s2));
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}

int solve(int tl, int pl) {
  int tt = 0;
  int pp = 0;
  int len = min(text.size() - tl, patn.size() - pl);
  for (int i = 0; i < len; i++) {
    if (text[tl + i] == patn[pl + i]) {
      tt++;
    } else {
      pp = max(pp, tt);
      tt = 0;
    }
  }
  return max(pp, tt);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string str1, str2, str3;
bool flag = false;
int ans;

int main() {

  while (cin >> str1) {
    // cin >> str1;
    // if(str1=="0")break;
    cin >> str2;
    // cout << " " << str1 << endl;
    // cout << " " << str2 << endl;
    for (int i = str1.size(); i > 0; i--) {
      for (int j = 0; j <= str1.size() - i; j++) {
        str3 = str1.substr(j, i);
        // cout << str3 << endl;
        if (str2.find(str3) >= 0 && str2.find(str3) < 4001) {
          ans = str3.size();
          flag = true;
          break;
        }
      }
      if (flag == true)
        break;
    }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#define REP(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int field[4002][4002];
int main(void) {
  char a[4002], b[4002];
  while (scanf("%s", a + 1) != EOF) {
    scanf("%s", b + 1);
    int ma = 0;
    REP(i, 1, 4001) field[i][1] = field[1][i] = 0;
    a[0] = '0';
    b[0] = '1';
    int as = strlen(a), bs = strlen(b);
    REP(i, 1, as) {
      REP(j, 1, bs) {
        if (a[i] == b[j]) {
          field[i][j] = field[i - 1][j - 1] + 1;
          ma = max(ma, field[i][j]);
        } else
          field[i][j] = 0;
      }
    }
    printf("%d\\n", ma);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#define REP(i, a, n) for (int i = a; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int field[4002][4002];
int main(void) {
  char a[4002], b[4002];
  while (scanf("%s", a + 1) != EOF) {
    scanf("%s", b + 1);
    int ma = 0;
    memset(field, 0, sizeof(int) * 4000 * 4000);
    a[0] = '0';
    b[0] = '1';
    REP(i, 1, strlen(a)) {
      REP(j, 1, strlen(b)) {
        if (a[i] == b[j]) {
          field[i][j] = field[i - 1][j - 1] + 1;
          ma = max(ma, field[i][j]);
        }
      }
    }
    printf("%d\\n", ma);
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int main() {
  char s1[4003], s2[4003];

  while (1 < scanf("%s %s", s1, s2)) {
    int maxcom = 0;
    int s1len = strlen(s1), s2len = strlen(s2);
    for (int i = 0; i < s1len + s2len; i++) {
      int is1, is2;
      if (i < s1len) {
        is1 = i;
        is2 = 0;
      } else {
        is1 = 0;
        is2 = i - s1len;
      }
      int tmax = 0;
      for (int k = 0; is1 + k < s1len && is2 + k < s2len; k++) {
        if (s1[is1 + k] == s2[is2 + k])
          ++tmax;
        else {
          maxcom = max(tmax, maxcom);
          tmax = 0;
        }
      }
      maxcom = max(tmax, maxcom);
    }

    cout << maxcom << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

char com[4003];

int main() {
  char s1[4003], s2[4003];

  while (1 < scanf("%s %s", s1, s2)) {
    int maxcom = 0;

    for (int i = 0; i < strlen(s1) + strlen(s2); i++) {
      int is1, is2;
      if (i < strlen(s1)) {
        is1 = i;
        is2 = 0;
      } else {
        is1 = 0;
        is2 = strlen(s1) + strlen(s2) - i;
      }
      int tmax = 0;
      for (int k = 0; is1 + k < strlen(s1) && is2 + k < strlen(s2); k++) {
        if (s1[is1 + k] == s2[is2 + k])
          com[k] = 1;
        else
          com[k] = 0;
      }

      for (int k = 0; is1 + k < strlen(s1) && is2 + k < strlen(s2); k++) {
        if (com[k])
          ++tmax;
        else {
          maxcom = max(tmax, maxcom);
          tmax = 0;
        }
      }
    }

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

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

char A[4002], B[4002];
short int length[4000][4000];
int mmax[200], mcor = 0;
int main() {
  int i, j, k, lenA, lenB;
  while (cin >> A[0]) {
    cin >> A + 1;
    cin >> B;
    lenA = strlen(A);
    lenB = strlen(B);
    for (i = 0; i < lenA; i++) {
      for (j = 0; j < lenB; j++) {
        length[i][j] = -1;
      }
    }
    // 逆さからループしただけなのにオーダーが1/100になったww
    for (i = lenA - 1; i >= 0; i--) {
      for (j = lenB - 1; j >= 0; j--) {
        for (k = 0;; k++) {
          if (i + k >= lenA || j + k >= lenB || A[i + k] != B[j + k]) {
            length[i][j] = k;
            break;
          } else if (length[i + k][j + k] >= 0) {
            length[i][j] = length[i + k][j + k] + k;
            break;
          }
        }
      }
    }
    for (i = 0; i < lenA; i++) {
      for (j = 0; j < lenB; j++) {
        if (mmax[mcor] < length[i][j])
          mmax[mcor] = length[i][j];
      }
    }
    mcor++;
  }
  for (i = 0; i < mcor; i++) {
    cout << mmax[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

char A[4002], B[4002];
short int length[4000][4000];
int mmax[200], mcor = 0;
int main() {
  int i, j, k, lenA, lenB;
  while (cin >> A[0]) {
    cin >> A + 1;
    cin >> B;
    lenA = strlen(A);
    lenB = strlen(B);
    for (i = 0; i < lenA; i++) {
      for (j = 0; j < lenB; j++) {
        length[i][j] = -1;
      }
    }
    for (i = 0; i < lenA; i++) {
      for (j = 0; j < lenB; j++) {
        for (k = 0;; k++) {
          if (i + k >= lenA || j + k >= lenB || A[i + k] != B[j + k]) {
            length[i][j] = k;
            break;
          } else if (length[i + k][j + k] >= 0) {
            length[i][j] = length[i + k][j + k] + k;
          }
        }
      }
    }
    for (i = 0; i < lenA; i++) {
      for (j = 0; j < lenB; j++) {
        if (mmax[mcor] < length[i][j])
          mmax[mcor] = length[i][j];
      }
    }
    mcor++;
  }
  for (i = 0; i < mcor; i++) {
    cout << mmax[i] << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int i, j, ans, c;
  int a[2][4001];
  string str, str2;
  while (cin >> str >> str2) {

    for (i = 0; i <= str.size(); i++)
      a[0][i] = 0;
    for (j = 0; j <= str2.size(); j++)
      a[0][j] = 0;

    ans = 0;
    for (i = 1; i <= str.size(); i++) {
      for (j = 1; j <= str2.size(); j++) {
        if (str[i - 1] == str2[j - 1]) {
          a[1][j] = a[0][j - 1] + 1;
          ans = max(ans, a[1][j]);
        } else
          a[1][j] = 0;
      }
      for (j = 0; j < str2.size(); j++)
        a[0][j] = a[1][j];
    }

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

Error: -11

Fixed submission:

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

int main() {
  int i, j;
  short a[4001][4001];
  string str, str2;
  while (cin >> str >> str2) {

    for (i = 0; i <= str.size(); i++)
      a[i][0] = 0;
    for (j = 0; j <= str2.size(); j++)
      a[0][j] = 0;

    for (i = 1; i <= str.size(); i++) {
      for (j = 1; j <= str2.size(); j++) {
        if (str[i - 1] == str2[j - 1])
          a[i][j] = a[i - 1][j - 1] + 1;
        else
          a[i][j] = a[i - 1][j];
      }
    }
    cout << a[str.size()][str2.size()] << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

string s, t;
int l[4000][4000];
int m;

void list(string s, string t) {
  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i] == t[j]) {
        if (i == 0 || j == 0) {
          l[i][j] = 1;
        } else {
          l[i][j] = l[i - 1][j - 1] + 1;
        }
      }
    }
  }
}

int search() {
  m = 0;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (l[i][j] >= m) {
        m = l[i][j];
        l[i][j] = 0;
      } else {
        l[i][j] = 0;
      }
    }
  }
  return m;
}

int main() {
  for (;;) {
    m = 0;
    if (cin >> s >> t) {
      m = 0;
      list(s, t);
      m = 0;
      cout << search() << endl;
    } else {
      break;
    }
    m = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

string s, t;
int l[100][100];
int m;

void list(string s, string t) {
  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i] == t[j]) {
        if (i == 0 || j == 0) {
          l[i][j] = 1;
        } else {
          l[i][j] = l[i - 1][j - 1] + 1;
        }
      }
    }
  }
}

int search() {
  m = 0;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < t.length(); j++) {
      if (l[i][j] >= m) {
        m = l[i][j];
        l[i][j] = 0;
      } else {
        l[i][j] = 0;
      }
    }
  }
  return m;
}

int main() {
  for (;;) {
    m = 0;
    if (cin >> s >> t) {
      m = 0;
      list(s, t);
      m = 0;
      cout << search() << endl;
    } else {
      break;
    }
    m = 0;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL long long
#define rep(a, b) for (int a = 0; a < b; a++)
#define pb push_back
#define str string
#define INF 100000000
using namespace std;
LL sub_string(const string &s1, const string &s2, LL l1, LL l2) {
  LL len = min(s1.length() - l1, s2.length() - l2);
  LL lon = 0;
  LL ans = 0;
  for (int j = 0; j < len; j++) {
    if (s1[l1 + j] == s2[l2 + j]) {
      lon++;
    } else {
      ans = max(ans, lon);
      lon = 0;
    }
  }
  return max(ans, lon);
}
int main() {
  str s1, s2;
  LL ans = 0;
  int i = 0;
  while (1) {
    s1 = "";
    s2 = "";
    if (!(cin >> s1 >> s2)) {
      break;
    }
    LL l1 = s1.length();
    LL l2 = 0;
    ans = 0;
    while (l1 != 0 || l2 <= s2.length()) {
      if (l1 != 0) {
        l1--;
      } else {
        l2++;
      }
      ans = max(ans, sub_string(s1, s2, l1, l2));
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
#define rep(a, b) for (int a = 0; a < b; a++)
#define pb push_back
#define str string
#define INF 100000000
using namespace std;
LL sub_string(const string &s1, const string &s2, LL l1, LL l2) {
  LL len = min(s1.length() - l1, s2.length() - l2);
  LL lon = 0;
  LL ans = 0;
  for (int j = 0; j < len; j++) {
    if (s1[l1 + j] == s2[l2 + j]) {
      lon++;
    } else {
      ans = max(ans, lon);
      lon = 0;
    }
  }
  return max(ans, lon);
}
int main() {
  str s1, s2;
  LL ans = 0;
  int i = 0;
  while (1) {
    cin >> s1;
    if (s1 == "EOF")
      break;
    cin >> s2;
    LL l1 = s1.length();
    LL l2 = 0;
    ans = 0;
    while (l1 != 0 || l2 <= s2.length()) {
      if (l1 != 0) {
        l1--;
      } else {
        l2++;
      }
      ans = max(ans, sub_string(s1, s2, l1, l2));
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

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

int dp[2][4444];
string s, t;

int main(int argc, char *argv[]) {
  while (cin >> s >> t) {
    int ls = s.length();
    int lt = t.length();
    rep(j, lt) dp[0][j] = dp[1][j] = 0;
    int res = 0;
    rep(i, ls) rep(j, lt) {
      if (j == 0)
        dp[i & 1][0] = 0;
      if (s[i] == t[j])
        dp[(i + 1) & 1][j + 1] = dp[i & 1][j] + 1;
      else
        dp[(i + 1) & 1][j + 1] = 0;
      res = max(res, dp[(i + 1) & 1][j + 1]);
    }
    cout << res << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

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

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

int dp[4444][4444];
string s, t;

int main(int argc, char *argv[]) {
  while (cin >> s >> t) {
    int ls = s.length();
    int lt = t.length();
    rep(i, ls) rep(j, lt) dp[i][j] = 0;
    int res = 0;
    rep(i, ls) rep(j, lt) {
      if (j == 0)
        dp[i + 1][0] = 0;
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = 0;
      res = max(res, dp[i + 1][j]);
    }
    cout << res << endl;
  }

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

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
string s, t;
set<string> st;
int dp[4444][4444];
int main() {
  while (cin >> s >> t) {
    s = "@" + s;
    t = "@" + t;
    int ans = 0;
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i < s.size(); i++) {
      for (int j = 1; j < t.size(); j++) {
        if (s[i] == t[j])
          dp[i][j] = dp[i - 1][j - 1] + 1;
        ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
string s, t;
set<string> st;
int main() {
  while (cin >> s >> t) {
    st.clear();
    r(j, s.size()) if (j)
        r(i, s.size()) if (j + i <= s.size()) if (!st.count(s.substr(i, j)))
            st.insert(s.substr(i, j));
    for (int j = t.size() - 1; j >= 1; j--)
      if (j)
        r(i, t.size()) if (j + i <= t.size()) if (st.count(t.substr(i, j))) {
          cout << j << endl;
          goto L;
        }
    cout << 0 << endl;
  L:;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

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

string s, t;
char a[4001];
char b[4001];
int dp[4001][4001];

int main() {
  while (scanf("%s%s", a, b) != EOF) {

    s = a;
    t = b;

    for (int i = 0; i < 4001; i++)
      for (int j = 0; j < 4001; j++)
        dp[i][j] = 0;

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

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

Error: TLE

Fixed submission:

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

string s, t;
char tmp[4001];
int dp[4001][4001];

int main() {
  while (1) {
    scanf("%s", tmp);
    if (tmp[0] == EOF)
      break;

    s = tmp;
    scanf("%s", tmp);
    t = tmp;

    for (int i = 0; i < 4001; i++)
      for (int j = 0; j < 4001; j++)
        dp[i][j] = 0;

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

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define int long long
#define mod 1000000007
using namespace std;
string s, t;
int dp[4005][4005], ans;
signed main() {
  while (cin >> s >> t) {
    for (int i = 0; i <= 4000; i++)
      for (int j = 0; j <= 4000; j++)
        dp[i][j] = 0;
    ans = 0;
    for (int i = 1; i <= s.size(); i++) {
      for (int j = 1; j <= t.size(); j++) {
        if (s[i - 1] == t[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          ans = max(dp[i][j], ans);
        }
      }
    }
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
bool find(string s, string key) {
  for (int i = 0; i < s.size() - key.size(); i++)
    if (s.substr(i, key.size()) == key)
      return true;
  return false;
}
int main() {
  string s, t;
  while (cin >> s >> t) {
    int ans = 0;
    int l = 0, r = 0;
    while (r < s.size()) {
      if (find(t, s.substr(l, r - l + 1))) {
        r++;
        if (r - l > ans)
          ans++;
      } else {
        l++;
        if (r < l)
          r++;
      }
    }
    cout << ans << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a, b;
  while (cin >> a >> b) {
    int n = 0;
    int la = a.size();
    int lb = b.size();
    for (int i = 1 - la; i < lb; i++) {
      int k = 0;
      for (int j = 0; j < la; j++) {
        if (j + i < 0 || j + i > lb - 1) {
          k = 0;
        } else if (a[j] == b[j + i]) {
          k++;
          n = max(n, k);
        } else {
          k = 0;
        }
      }
    }
    cout << n << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a, b;
  while (cin >> a >> b) {
    int n = 0;
    int la = a.size();
    int lb = b.size();
    for (int i = 0; i < la; i++) {
      for (int j = 0; j < lb; j++) {
        int k = 0, m = 0;
        do {
          if (a[i + k] == b[j + k]) {
            k++;
            m = 1;
            if (i + k > la - 1 || j + k > lb - 1) {
              m = 0;
            }
          } else {
            m = 0;
          }
        } while (m == 1);
        n = max(n, k);
      }
    }
    cout << n << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

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

int dp[2][4010];

int main() {
  string in1, in2;
  while (cin >> in1 >> in2) {
    int n = in1.size();
    int m = in2.size();
    int ret = 0;
    rep(i, 2) rep(j, m + 1) dp[i][j] = 0;
    REP(i, 1, n + 1) {
      int cur = i % 2;
      int next = (i + 1) % 2;
      REP(j, 1, m + 1) {
        if (in1[i - 1] == in2[j - 1]) {
          dp[next][j] = dp[cur][j - 1] + 1;
          ret = max(ret, dp[next][j]);
        }
      }
      rep(i, m + 1) dp[cur][i] = 0;
    }
    printf("%d\\n", ret);
  }
  return 0;
}

Error: MLE

Fixed submission:

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

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

int dp[4010][4010];

int main() {
  string in1, in2;
  while (cin >> in1 >> in2) {
    int n = in1.size();
    int m = in2.size();
    int ret = 0;
    rep(i, n + 1) rep(j, m + 1) dp[i][j] = 0;
    REP(i, 1, n + 1) {
      REP(j, 1, m + 1) {
        if (in1[i - 1] == in2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          ret = max(ret, dp[i][j]);
        }
      }
    }
    printf("%d\\n", ret);
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef long long int64;
const int inf = (int)1e9;

int main() {
  while (true) {

    char str1[4096], str2[4096];

    if (scanf("%s", str1) == EOF)
      break;
    scanf("%s", str2);

    int len1 = strlen(str1), len2 = strlen(str2);
    int ans = 0;
    static int dp[2][4096] = {0};

    for (int i = 0; i <= len1; ++i)
      dp[0][i] = 0;

    int *cur = dp[0];
    int *next = dp[1];

    for (int i = 1; i <= len1; ++i) {

      cur[0] = 0;

      for (int j = 1; j <= len2; ++j) {
        if (str1[i - 1] == str2[j - 1]) {
          next[j] = cur[j - 1] + 1;
          ans = max(next[j], ans);
        } else {
          next[j] = 0;
        }
      }

      swap(cur, next);
    }

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

  return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

Error: MLE

Fixed submission:

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

typedef long long int64;
const int inf = (int)1e9;

int main() {
  while (true) {

    char str1[4096], str2[4096];

    if (scanf("%s", str1) == EOF)
      break;
    scanf("%s", str2);

    int len1 = strlen(str1), len2 = strlen(str2);
    int ans = 0;
    static int dp[4096][4096] = {0};

    for (int i = 0; i <= len1; ++i)
      dp[i][0] = 0;
    for (int i = 0; i <= len2; ++i)
      dp[0][i] = 0;

    for (int i = 1; i <= len1; ++i) {
      for (int j = 1; j <= len2; ++j) {
        if (str1[i - 1] == str2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          ans = max(dp[i][j], ans);
        } else {
          dp[i][j] = 0;
        }
      }
    }

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

  return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

// 36
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  for (string s, ss; cin >> s >> ss;) {
    int dp[2][4001] = {};
    int ans = 0;
    for (int y = 1; y <= ss.size(); y++) {
      for (int x = 1; x <= s.size(); x++) {
        dp[y & 1][x] = ((ss[y] == s[x - 1]) ? dp[(y - 1) & 1][x - 1] + 1 : 0);
        ans = max(ans, dp[y & 1][x]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

// 36
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  for (string s, ss; cin >> s >> ss;) {
    static int dp[4001][4001];
    for (int i = 0; i < 4001; i++) {
      dp[0][i] = dp[i][0] = 0;
    }
    int ans = 0;
    for (int y = 1; y <= ss.size(); y++) {
      for (int x = 1; x <= s.size(); x++) {
        dp[y][x] = ((ss[y - 1] == s[x - 1]) ? dp[y - 1][x - 1] + 1 : 0);
        ans = max(ans, dp[y][x]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}