alexjercan/bugnet huggingface dataset:
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int c[4005][4005];

int lcs(string s, string s2) {
  int m = s.size();
  int n = s2.size();
  int ret = 0;

  memset(c, 0, sizeof(c));
  s = ' ' + s;
  s2 = ' ' + s2;

  REP(i, 1, m + 1) c[i][0] = 0;
  REP(j, 1, n + 1) c[0][j] = 0;

  REP(i, 1, m + 1) {
    REP(j, 1, n + 1) {
      if (s[i] == s2[j])
        c[i][j] = c[i - 1][j - 1] + 1;
      ret = max(ret, c[i][j]);
    }
  }

  return ret;
}

int main() {
  string a, b;
  while (cin >> a >> b) {
    cout << lcs(a, b) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int lcs(string s, string s2) {
  int m = s.size();
  int n = s2.size();
  int c[max(m, n) + 1][max(m, n) + 1];
  int ret = 0;

  memset(c, 0, sizeof(c));
  s = ' ' + s;
  s2 = ' ' + s2;

  REP(i, 1, m + 1) c[i][0] = 0;
  REP(j, 1, n + 1) c[0][j] = 0;

  REP(i, 1, m + 1) {
    REP(j, 1, n + 1) {
      if (s[i] == s2[j])
        c[i][j] = c[i - 1][j - 1] + 1;
      ret = max(ret, c[i][j]);
    }
  }

  return ret;
}

int main() {
  string a, b;
  while (cin >> a >> b) {
    cout << lcs(a, b) << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define Rep(i, N) for (int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int, int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a, b); }
inline void chmin(int &a, int b) { a = min(a, b); }

int main() {
  string s, t;
  while (cin >> s >> t) {
    vector<vector<int>> dp(2, vector<int>(4005, 0));
    int ss = s.size(), ts = t.size();
    int maxv = 0;
    Rep(i, ts) {
      Rep(j, ss) {
        if (s[j] == t[i]) {
          dp[1][j + 1] = dp[0][j] + 1;
          chmax(maxv, dp[1][j + 1]);
        } else {
          dp[1][j + 1] = 0;
        }
      }
      dp[0] = dp[1];
    }
    cout << maxv << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define Rep(i, N) for (int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int, int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a, b); }
inline void chmin(int &a, int b) { a = min(a, b); }

int main() {
  int dp[4005][4005];
  string s, t;
  while (cin >> s >> t) {
    fill(dp[0], dp[4005], 0);
    int ss = s.size(), ts = t.size();
    int maxv = 0;
    Rep(i, ts) {
      Rep(j, ss) {
        if (s[j] == t[i]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          chmax(maxv, dp[i + 1][j + 1]);
        }
      }
    }
    cout << maxv << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
char c[4001], d[4001], *a, *b;
int main() {
  while (~scanf("%s%s", c, d)) {
    int mx = 0, o, i, k, s;
    for (a = c, b = d, k = 0; k++ < 2; a = d, b = c)
      for (o = 0; a[o]; o++)
        for (i = s = 0; a[i + o] && b[i]; i++) {
          if (a[i + o] == b[i]) {
            s++;
            if (mx < s)
              mx = s;
          } else
            s = 0;
        }
    printf("%d\\n", mx);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int lcs(string &a, string &b) {
  int r = 0, la = a.size(), lb = b.size(), t, tla, tlb;
  for (int i = 0; i < la || i < lb; i++)
    if (a[tla = min(i, la - 1)] == b[tlb = min(i, lb - 1)]) {
      rep(j, tla) {
        t = 0;
        while (tla > j + t && tlb > t && a[tla - 1 - j - t] == b[tlb - 1 - t])
          t++;
        if (t > r)
          r = t;
      }
      rep(j, tlb) {
        t = 0;
        while (tla > t && tlb > j + t && a[tla - 1 - t] == b[tlb - j - 1 - t])
          t++;
        if (t > r)
          r = t;
      }
    }
  return r;
}
int main() {
  string a, b;
  while (cin >> a >> b)
    cout << lcs(a, b) << endl;
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX_S 4000
#define MAX_T 4000
template <typename T> int longest_common_substring(T s, T t) {
  int lens = s.size(), lent = t.size();
  static int dp[MAX_S + 1][MAX_T + 1];
  rep(i, MAX_S + 1) rep(j, MAX_T + 1) dp[i][j] = 0;

  int maxi = 0;

  rep(i, s.size()) {
    rep(j, t.size()) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = 0;
      maxi = max(maxi, dp[i + 1][j + 1]);
    }
  }

  return maxi;
}

int main() {
  string a, b;
  while (cin >> a >> b) {
    cout << longest_common_substring(a, b) << endl;
  }
}

Error: -11

Fixed submission:

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

#define MAX_S 4000
#define MAX_T 4000
template <typename T> int longest_common_substring(T s, T t) {
  int lens = s.size(), lent = t.size();
  int dp[MAX_S + 1][MAX_T + 1] = {};
  int maxi = 0;

  rep(i, s.size()) {
    rep(j, t.size()) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = 0;
      maxi = max(maxi, dp[i + 1][j + 1]);
    }
  }

  return maxi;
}

int main() {
  string a, b;
  while (cin >> a >> b) {
    cout << longest_common_substring(a, b) << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <memory>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 28;
const double EPS = 1E-10;

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

int main() {
  string s, t;
  int n, m;
  while (getline(cin, s)) {
    getline(cin, t);
    n = s.size();
    m = t.size();

    int res = 0;
    for (int i = -n + 1; i < m; i++) {
      int c = 0;
      int ind = max(i, 0);
      while (ind - i < n && ind < m) {
        c = 0;
        while (ind - i < n && ind < m && s[ind - i] == t[ind]) {
          c++;
          ;
          ind++;
        }
        ind++;
        res = max(c, res);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <memory>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, m, n) for (int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 28;
const double EPS = 1E-10;

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

int main() {
  string s, t;
  int n, m;
  while (getline(cin, s)) {
    getline(cin, t);
    n = s.size();
    m = t.size();

    string res = "";
    for (int i = -n + 1; i < m; i++) {
      string c = "";
      int ind = max(i, 0);
      while (ind - i < n && ind < m) {
        c = "";
        while (ind - i < n && ind < m && s[ind - i] == t[ind]) {
          c += s[ind - i];
          ind++;
        }
        ind++;
        if (c.size() >= res.size())
          res = c;
      }
    }
    cout << res.size() << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string str, test;
  while (cin >> str >> test) {
    vector<string> v;
    int N = str.size();
    for (int i = 0; i < N; i++) {
      v.push_back(str.substr(i, N - i));
    }
    sort(v.begin(), v.end());
    int ans = N;
    for (int i = 1; i < test.size(); i++) {
      bool flag = false;
      for (int j = 0; j < test.size() - i + 1; j++) {
        string tmp = test.substr(j, i);
        vector<string>::iterator itr = lower_bound(v.begin(), v.end(), tmp);
        int z = (int)(itr - v.begin());
        if (z != N && v[z].size() >= i) {
          if (tmp == v[z].substr(0, i)) {
            flag = true;
            break;
          }
        }
      }
      if (!flag) {
        ans = i - 1;
        break;
      }
    }
    cout << ans << endl;
    str.clear();
    test.clear();
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  string str;
  while (cin >> str) {
    string test;
    cin >> test;
    vector<string> v;
    int N = str.size();
    for (int i = 0; i < N; i++) {
      v.push_back(str.substr(i, N - i));
    }
    sort(v.begin(), v.end());
    int ans;
    for (int i = 1; i < test.size(); i++) {
      bool flag = false;
      for (int j = 0; j < test.size() - i + 1; j++) {
        string tmp = test.substr(j, i);
        vector<string>::iterator itr = lower_bound(v.begin(), v.end(), tmp);
        int z = (int)(itr - v.begin());
        if (z != N && v[z].size() >= i) {
          bool fff = true;
          for (int k = 0; k < i; k++) {
            if (tmp[k] != v[z][k]) {
              fff = false;
              break;
            }
          }
          if (fff) {
            flag = true;
            break;
          }
        }
      }
      if (!flag) {
        ans = i - 1;
        break;
      }
    }
    cout << ans << endl;
    str.clear();
  }

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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define VS vector<string>

int main(void) {
  string s, t;
  int max = 0;
  while (cin >> s >> t) {
    vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
    REP(i, s.size()) {
      REP(j, t.size()) { dp[i][j] = -1; }
    }
    REP(i, s.size()) { dp[i][0] = 0; }
    REP(i, t.size()) { dp[0][i] = 0; }

    FOR(i, 1, s.size() + 1) {
      FOR(j, 1, t.size() + 1) {
        if (s[i - 1] != t[j - 1])
          dp[i][j] = 0;
        else
          dp[i][j] = dp[i - 1][j - 1] + 1;
        max = fmax(max, dp[i][j]);
      }
    }
    cout << max << endl;
    max = 0;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define VS vector<string>

int main(void) {
  string s, t;
  int max = 0;
  while (cin >> s >> t) {
    int dp[s.size()][t.size()];
    REP(i, s.size()) {
      REP(j, t.size()) { dp[i][j] = -1; }
    }
    REP(i, s.size()) { dp[i][0] = 0; }
    REP(i, t.size()) { dp[0][i] = 0; }

    FOR(i, 1, s.size()) {
      FOR(j, 1, t.size()) {
        if (s[i] != t[j])
          dp[i][j] = 0;
        else
          dp[i][j] = dp[i - 1][j - 1] + 1;
        max = fmax(max, dp[i][j]);
      }
    }
    cout << max << endl;
    max = 0;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>
unsigned short d[4000][4000];
char a[4001], b[4001];
int i, j;

int max(int a, int b) {
  if (a >= b)
    return a;
  else
    return b;
}

int main() {
  while (scanf("%s", a) != EOF) {
    scanf("%s", b);
    int al = strlen(a);
    int bl = strlen(b);
    for (i = 0; i < al; i++)
      for (j = 0; j < bl; j++)
        d[i][j] = 0;
    for (i = 0; i < al; i++)
      for (j = 0; j < bl; j++) {
        if (a[i] == b[j]) {
          if (i > 0 && j > 0)
            d[i][j] = d[i - 1][j - 1] + 1;
          else
            d[i][j] = 1;
        } else {
          d[i][j] = 0;
        }
      }
    /*for(i=0;i<strlen(a);i++){
            for(j=0;j<strlen(b);j++)printf("%d ",d[i][j]);
            printf("\\n");
    }
    printf("\\n");*/
    int ans = 0;
    for (i = 0; i < al; i++)
      for (j = 0; j < bl; j++)
        ans = max(ans, d[i][j]);
    printf("%d\\n", ans);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
unsigned short d[4000][4000];
char a[4000], b[4000];
int i, j;

int max(int a, int b) {
  if (a >= b)
    return a;
  else
    return b;
}

int main() {
  while (scanf("%s", &a) != EOF) {
    scanf("%s", &b);
    for (i = 0; i < strlen(a); i++)
      for (j = 0; j < strlen(b); j++)
        d[i][j] = 0;
    for (i = 0; i < strlen(a); i++) {
      for (j = 0; j < strlen(b); j++) {
        if (a[i] == b[j]) {
          if (i > 0 && j > 0)
            d[i][j] = d[i - 1][j - 1] + 1;
          else
            d[i][j] = 1;
        } else {
          d[i][j] = 0;
        }
      }
    }
    /*for(i=0;i<strlen(a);i++){
            for(j=0;j<strlen(b);j++)printf("%d ",d[i][j]);
            printf("\\n");
    }
    printf("\\n");*/
    int ans = 0;
    for (i = 0; i < strlen(a); i++)
      for (j = 0; j < strlen(b); j++)
        ans = max(ans, d[i][j]);
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <stdio.h>
#include <string.h>
char a[4001];
char b[4001];
short dp[4001][4001];
int max(int a, int b) { return a > b ? a : b; }
int main() {
  while (scanf(" %s", a) != EOF) {
    scanf(" %s", b);
    int n = strlen(a);
    int m = strlen(b);
    int i, j;
    for (i = 0; i <= n; i++)
      for (j = 0; j <= m; j++)
        dp[i][j] = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (a[i] == b[j])
          dp[i + 1][j + 1] = dp[i][j] + 1;
      }
    }
    int ans = 0;
    for (i = 0; i <= n; i++)
      for (j = 0; j <= m; j++)
        ans = max(ans, dp[i][j]);
    printf("%d\\n", ans);
  }
}

Error: MLE

Fixed submission:

#include <stdio.h>
#include <string.h>
char a[4001];
char b[4001];
int dp[4001][4001];
int max(int a, int b) { return a > b ? a : b; }
int main() {
  while (scanf(" %s", a) != EOF) {
    scanf(" %s", b);
    int n = strlen(a);
    int m = strlen(b);
    int i, j;
    for (i = 0; i <= n; i++)
      for (j = 0; j <= m; j++)
        dp[i][j] = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (a[i] == b[j])
          dp[i + 1][j + 1] = dp[i][j] + 1;
      }
    }
    int ans = 0;
    for (i = 0; i <= n; i++)
      for (j = 0; j <= m; j++)
        ans = max(ans, dp[i][j]);
    printf("%d\\n", ans);
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string a, b;
  while (cin >> a >> b) {
    int MAX = 0;
    for (int i = -((int)a.length()) + 1; i < (int)(b.length()); i++) {
      int k = 0;
      for (int j = 0; j < a.length(); j++) {
        if (i + j < 0 || i + j >= b.length() || a[j] != b[i + j])
          k = 0;
        else
          k++;
        MAX = max(MAX, k);
      }
    }
    cout << MAX << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  string a, b;
  while (cin >> a >> b) {
    int MAX = 0;
    for (int c = 0; c < a.length(); c++) {
      for (int d = 0; d < b.length(); d++) {
        int e = 0;
        for (; c + e < a.length() && d + e < b.length(); e++) {
          if (a[c + e] != b[d + e])
            break;
        }
        MAX = max(e, MAX);
      }
    }
    cout << MAX << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
// #define int long long
#define str string
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const int inf2 = 1145141919;
const ld pi =
    3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
struct P {
  ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B { //??£??\\???????????¨???
  ll to, cost;
};
struct S { //???????????±?????\\???????????°
  int from, to, cost;
};
bool operator<(S a, S b) { return a.cost < b.cost; }
bool operator>(S a, S b) { return a.cost > b.cost; }
struct H {
  int x, y;
};
ll gcm(ll i, ll j) { //?????§??¬?´???°
  if (i > j)
    swap(i, j);
  if (i == 0)
    return j;
  return gcm(j % i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
  return sqrt(pow(a - c, 2) + pow(b - d, 2));
} // rad?????§?¨???????2??????????????¢
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
string a, b;
int dp[4000][4000];
signed main() {
  while (cin >> a >> b) {
    int n = a.size(), m = b.size();
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        dp[i][j] = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i] == b[j]) {
          if (i > 0 && j > 0)
            dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
          else
            dp[i][j] = 1;
          ans = max(ans, dp[i][j]);
        }
      }
    }
    cout << ans << endl;
  }
  getchar();
  getchar();
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
bool c[4000][4000];
int main() {
  string a, b;
  while (cin >> a >> b) {
    for (int i = 0; i < a.length(); i++) {
      for (int j = 0; j < b.length(); j++)
        c[i][j] = true;
    }
    int sum = 0;
    for (int i = 0; i < a.length(); i++) {
      for (int j = 0; j < b.length(); j++) {
        if (c[i][j] && a[i] == b[j]) {
          int i2 = i, j2 = j, sum2 = 0;
          while (a[i2] == b[j2] && i2 < a.length() && j2 < b.length()) {
            c[i2][j2] == false;
            i2++;
            j2++;
            sum2++;
          }
          sum = max(sum, sum2);
        }
      }
    }
    cout << sum << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x, s, g) ((x) >= (s) && (x) < (g))
#define ISIN(x, y, w, h) (IN((x), 0, (w)) && IN((y), 0, (h)))
#define print(x) printf("%d\\n", x);

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0, 1, 0, -1};
const int _dy[] = {-1, 0, 1, 0};

int getInt() {
  int ret = 0, c;
  c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

char str1[4010];
char str2[4010];

int main() {
  while (~scanf("%s %s", str1, str2)) {
    int ans = 0;
    int len1 = strlen(str1);
    int len2 = strlen(str2);

    for (int off = -len1; off <= len2; off++) {
      int len = 0;
      for (int i = max(off, 0); i < min(len1 + off, len2); i++) {
        if (str1[i - off] == str2[i])
          ans = max(ans, ++len);
        else
          len = 0;
      }
    }
    print(ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x, s, g) ((x) >= (s) && (x) < (g))
#define ISIN(x, y, w, h) (IN((x), 0, (w)) && IN((y), 0, (h)))
#define print(x) printf("%d\\n", x);

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0, 1, 0, -1};
const int _dy[] = {-1, 0, 1, 0};

int getInt() {
  int ret = 0, c;
  c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

char str1[4010];
char str2[4010];

int main() {
  while (~scanf("%s %s", str1, str2)) {
    int ans = 0;
    int len1 = strlen(str1);
    int len2 = strlen(str2);

    for (int i = 0; i + ans < len1; i++) {
      for (int j = 0; j + ans < len2; j++) {
        if (str1[i] == str2[j]) {
          int tmp = 0;
          int ii = i;
          int jj = j;
          while (str1[ii] && str1[ii++] == str2[jj++])
            ++tmp;
          ans = max(ans, tmp);
        }
      }
    }
    print(ans);
  }
  return 0;
}