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

#include <cstring>
#include <iostream>
#include <map>
using namespace std;
map<string, int> m;
int main() {
  string s, t;
  while (cin >> s >> t) {
    int x, a = 0, b, S = s.size(), T = t.size(), i, j;
    b = min(S, T) + 1;
    while (true) {
      x = 0;
      j = (a + b) / 2;
      if (b - a == 1)
        break;
      for (i = 0; i <= S - j; i++)
        m[s.substr(i, j)]++;
      for (i = 0; i <= T - j; i++)
        if (m[t.substr(i, j)] >= 1)
          x++;
      m.clear();
      if (!x)
        b = j;
      else
        a = j;
    }
    cout << a << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
using namespace std;
map<string, int> m;
int main() {
  string s, t;
  while (cin >> s >> t) {
    int a = 0, S = s.size(), T = t.size(), i, j;
    for (j = min(S, T); j >= 1; j--) {
      for (i = 0; i < S - j; i++)
        m[s.substr(i, j)]++;
      for (i = 0; i < T - j; i++)
        if (m[t.substr(i, j)] >= 1)
          a = max(a, j);
      m.clear();
      if (a)
        break;
    }
    cout << a << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

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

unsigned short dp[4010][4010];

int main() {
  int i, j;
  string s, t;

  while (cin >> s >> t) {
    int N = s.length(), M = t.length(), res = 0;

    rep(i, 4010) rep(j, 4010) dp[i][j] = 0;
    rep(i, N) rep(j, M) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        res = max(res, (int)dp[i + 1][j + 1]);
      } else {
        dp[i + 1][j + 1] = 0;
      }
    }

    cout << res << endl;
    //    cout << dp[N][M] << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

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

unsigned int dp[4010][4010];

int main() {
  int i, j;
  string s, t;

  while (cin >> s >> t) {
    int N = s.length(), M = t.length(), res = 0;

    rep(i, 4010) rep(j, 4010) dp[i][j] = 0;
    rep(i, N) rep(j, M) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        int tmp = max(dp[i][j + 1], dp[i + 1][j]);
        res = max(res, tmp);
        dp[i + 1][j + 1] = 0;
      }
    }

    cout << res << endl;
    //    cout << dp[N][M] << endl;
  }

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

#include <iostream>

using namespace std;

int solve(const string &s1, const string &s2, int sp1, int sp2) {

  int tmp = 0;
  int res = 0;
  int len = min(s2.length() - sp2, s1.length() - sp1);

  for (int i = 0; i < len; i++) {
    if (s1[sp1 + i] != s2[sp2 + i]) {
      res = max(res, tmp);
      tmp = 0;
    } else {
      tmp++;
    }
  }
  return max(tmp, res);
}

int main() {

  string s1, s2;
  while (getline(cin, s1) && getline(cin, s2)) {
    int p1 = s1.length();
    int p2 = 0;
    int ans = 0;

    while (p1 != 0 || p2 <= (int)s2.length()) {
      if (p1 != 0)
        p1--;
      else
        p2++;
      ans = max(ans, solve(s1, s2, p1, p2));
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

string s1, s2;

int solve(int a, int b) {
  int pass = 0;
  while (s1[a++] == s2[b++] && a < s1.length() && b < s2.length())
    pass++;

  return pass;
}

int main() {
  while (cin >> s1 >> s2) {
    int ans = 0;
    for (int i = 0; i < s1.length(); i++)
      for (int j = 0; j < s2.length(); j++)
        ans = max(ans, solve(i, j));

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


//=====================================================
//
// (setq backup-inhibited t)
// (setq auto-save-default nil)
//
// (column-number-mode t)
// (setq-default tab-width 2 indent-tabs-mode nil)
//
// (global-set-key "\\C-h" 'delete-backward-char)
//
// (setq indent-line-function 'indent-relative-maybe)
// (global-set-key "\\C-m" 'newline-and-indent)
//
//=====================================================

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

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

using namespace std;

int main() {
  while (1) {
    string s;
    string t;
    cin >> s;
    cin >> t;
    vector<vector<int>> dp(4000, vector<int>(4000));
    if (!cin)
      break;
    set<string> st;
    int ml = 0;
    for (int i = 0; i < s.size(); ++i) {
      for (int j = 0; j < t.size(); ++j) {
        if (i > 0 && j > 0 && s[i] == t[j])
          dp[i][j] = dp[i - 1][j - 1] + 1;
        else if (s[i] == t[j])
          dp[i][j] = 1;
        else
          dp[i][j] = 0;
        ml = max(ml, dp[i][j]);
      }
    }
    cout << ml << endl;
  }
  return 0;
}

Error: 0

Fixed submission:


//=====================================================
//
// (setq backup-inhibited t)
// (setq auto-save-default nil)
//
// (column-number-mode t)
// (setq-default tab-width 2 indent-tabs-mode nil)
//
// (global-set-key "\\C-h" 'delete-backward-char)
//
// (setq indent-line-function 'indent-relative-maybe)
// (global-set-key "\\C-m" 'newline-and-indent)
//
//=====================================================

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

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

using namespace std;

int main() {
  while (1) {
    string s;
    string t;
    cin >> s;
    cin >> t;
    if (!cin)
      break;
    set<string> st;
    for (int i = 0; i < s.size(); ++i) {
      for (int j = 0; i + j < s.size(); ++j) {
        st.insert(s.substr(i, j));
      }
    }
    size_t ml = 0;
    for (const string &str : st) {
      if (t.find(str) != string::npos)
        ml = max(ml, str.size());
    }
    cout << ml << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}

signed main() {
  string s, t;
  while (cin >> s) {
    cin >> t;
    auto dp = vector<vector<int>>(s.size() + 1, vector<int>(t.size() + 1, 0LL));
    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;
      }
    }
    int maxi = -1;
    for (auto u : dp)
      for (auto e : u)
        cmax(maxi, e);
    cout << maxi << endl;
  }
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
std::map<std::string, int> mp;
int main() {
  std::string s;
  std::string b;

  while (std::cin >> s) {
    std::cin >> b;
    mp.clear();
    if (b.size() > s.size())
      std::swap(s, b);
    for (int i = 0; i < s.size(); i++) {
      for (int j = i + 1; j < s.size(); j++) {
        std::string temp = s.substr(i, j - i);
        mp[temp] = 1;
      }
    }
    int ans = 0;
    for (int i = 0; i < b.size(); i++) {
      for (int j = i + 1; j < b.size(); j++) {
        std::string comp = b.substr(i, j - i);
        if (mp[comp])
          ans = std::max(ans, (int)comp.size());
      }
    }
    std::cout << ans << std::endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string a, b;
  while (cin >> a >> b) {
    int MAX = 0;
    for (int i = 0; i < a.size(); i++) {
      int c = 0;
      for (int j = 0; j < b.size(); j++) {
        if (i + j < a.size()) {
          if (a[i + j] == b[j]) {
            c++;
          } else {
            MAX = max(MAX, c);
            c = 0;
          }
        } else {
          MAX = max(MAX, c);
          break;
        }
      }
    }
    for (int i = 0; i < b.size(); i++) {
      int c = 0;
      for (int j = 0; j < a.size(); j++) {
        if (i + j < b.size()) {
          if (b[i + j] == a[j]) {
            c++;
          } else {
            MAX = max(MAX, c);
            c = 0;
          }
        } else {
          MAX = max(MAX, c);
          break;
        }
      }
    }
    cout << MAX << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string a;
  while (getline(cin, a)) {
    string b;
    getline(cin, b);
    string ss;
    string ll;
    if (a.size() > b.size()) {
      ss = b;
      ll = a;
    } else {
      ss = a;
      ll = b;
    }
    int counter = 0;
    int counter2 = 0;
    for (int i = 0; i < ss.size(); i++) {
      counter2 = 0;
      int counter3 = 0;
      while (counter2 < ll.size() && ll.find(ss[i], counter2) != string::npos) {
        counter3 = 1;
        for (int j = ll.find(ss[i], counter2) + 1; j < ll.size(); j++) {
          if (ll[j] == ss[i + counter3]) {
            counter3++;
          } else {
            break;
          }
        }
        counter = max(counter, counter3);
        counter2 = ll.find(ss[i], counter2) + 1;
      }
    }
    cout << counter << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;

int dp[4001][4001];

void solve(string s, string t) {
  memset(dp, 0, sizeof(dp));
  int maxi = 0;
  rep(i, s.length()) {
    rep(j, t.length()) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        maxi = max(maxi, dp[i + 1][j + 1]);
      } else {
        dp[i + 1][j + 1] = 0;
      }
    }
  }
  cout << maxi << endl;
}

int main() {
  string s, t;
  while (cin >> s >> t) {
    solve(s, t);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;

void solve(string s, string t) {
  if (s.length() > t.length())
    swap(s, t);
  for (int i = s.length(); i >= 1; i--) {
    for (int j = 0; j + i < s.length(); j++) {
      string ss = s.substr(j, i);
      if (t.find(ss) != string::npos) {
        cout << i << endl;
        return;
      }
    }
  }
  cout << 0 << endl;
}

int main() {
  string s, t;
  while (cin >> s >> t) {
    solve(s, t);
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int ans, cnt;
  string s, t;
  while (cin >> s >> t) {
    ans = 0;
    for (int i = 0; i < s.size(); i++) {
      cnt = 0;
      for (int j = 0; j < s.size() - i; j++) {
        if (s[j + i] == t[j]) {
          cnt++;
          ans = max(ans, cnt);
        } else {
          cnt = 0;
        }
      }
    }
    for (int i = 0; i < t.size(); i++) {
      cnt = 0;
      for (int j = 0; j < t.size() - i; j++) {
        if (t[i + j] == s[j]) {
          cnt++;
          ans = max(ans, cnt);
        } else {
          cnt = 0;
        }
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, i, j, max;
  string s1, s2, t;
  while (cin >> s1 >> s2) {
    max = 0;
    for (i = 0; i <= s1.size(); i++) {
      if (s1.size() - max < 0)
        break;
      for (j = 1; j <= s1.size() - i; j++) {
        t = s1.substr(i, j);
        if (s2.find(t) != string::npos)
          if (max < t.size())
            max = t.size();
      }
    }
    cout << max << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int check(string, string);

int main() {
  string s1, s2;

  while (cin >> s1 >> s2) {
    int res = 0;
    if (s1.size() < s2.size())
      swap(s1, s2);

    for (int i = 0; i < s1.size(); i++)
      res = max(res, check(s1.substr(i, s1.size()), s2));

    for (int i = 0; i < s2.size(); i++)
      res = max(res, check(s2.substr(s2.size() - 1 - i, s2.size()), s1));

    cout << res << endl;
  }
}

int check(string s1, string s2) {
  int res = 0, sn = 0;
  for (int i = 0; i < min(s1.size(), s2.size()); i++) {
    if (s1[i] == s2[i])
      sn++;
    else
      sn = 0;

    res = max(res, sn);
  }
  return res;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int check(string, string);

int main() {
  // ifstream ifs("data.txt");
  string str1, str2;
  while (cin >> str1 >> str2) {

    int res = 0;

    for (int i = 0; i < str1.size(); i++) {
      rotate(str1.begin(), str1.begin() + 1, str1.end());

      res = max(res, check(str1, str2));
    }

    for (int i = 0; i < str2.size(); i++) {
      rotate(str2.begin(), str2.begin() + 1, str2.end());

      res = max(res, check(str1, str2));
    }

    cout << res << endl;
  }
  // ifs.close();
}

inline int check(string str1, string str2) {
  int sn = 0, res = 0;
  for (int i = 0; i < min(str1.size(), str2.size()); i++) {
    if (str1[i] == str2[i]) {
      sn++;
    } else {
      sn = 0;
    }
    res = max(res, sn);
  }
  return res;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

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

char a[4004], b[4004];

int solve(char *s, char *t, int lenS, int lenT) {
  int i, j;
  int count = 0;
  int res = 0;

  for (i = j = 0; i < lenS && j < lenT; i++, j++) {
    if (s[i] == t[j]) {
      count++;
    } else {
      if (res < count)
        res = count;
      count = 0;
    }
  }

  if (res < count)
    res = count;
  return res;
}

int main(void) {
  int i, j;
  int lenA, lenB;
  int ans, tmp;

  while (scanf("%s%s", a, b) != EOF) {
    lenA = strlen(a);
    lenB = strlen(b);
    ans = 0;

    // AÌæªÌi¶ðíÁ½¶ñÆ,Bðär
    for (i = 0; i < lenA; i++) {
      tmp = solve(&a[i], b, lenA - i, lenB);
      if (ans < tmp)
        ans = tmp;
    }

    // BÌæªÌi¶ðíÁ½¶ñÆ,Aðär
    for (i = 0; i < lenB; i++) {
      tmp = solve(&b[i], a, lenB - i, lenA);
      if (ans < tmp)
        ans = tmp;
    }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

void solve() {
  string str1, str2;
  while (cin >> str1 >> str2) {
    int length1 = str1.size();
    int length2 = str2.size();
    int max = 0;
    for (int i = 0; i < length1; ++i) {
      int count = 0;
      for (int j = 0; j < length2; ++j) {
        int pos1 = i;
        int pos2 = j;
        while (str1[pos1] == str2[pos2]) {
          if ((pos1 == length1 - 1) || (pos2 == length2 - 1)) {
            break;
          }
          ++pos1;
          ++pos2;
          count++;
          if (max < count) {
            max = count;
          }
        }
        count = 0;
      }
    }
    cout << max << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  string a, b;
  while (cin >> a >> b) {
    int ans = 0;
    for (int x = 0; x < 2; x++) {
      for (int i = 0; i < a.size(); i++) {
        int len = 0;
        for (int j = 0; j < b.size(); j++) {
          if (a[i + len] == b[j])
            len++;
          else
            len = a[i] == b[j];
          ans = max(len, ans);
        }
      }
      swap(a, b);
    }
    cout << ans << endl;
  }
}
// a b c d e
// abcdef
// def

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  string a, b;
  while (cin >> a >> b) {
    int ans = 0;
    for (int x = 0; x < 2; x++) {
      for (int i = 0; i < a.size(); i++) {
        int len = 0;
        for (int j = 0; j < b.size(); j++) {
          if (i + len < a.size() && a[i + len] == b[j])
            len++;
          else
            len = a[i] == b[j];
          ans = max(len, ans);
        }
      }
      swap(a, b);
    }

    cout << ans << endl;
  }
}
// a b c d e
// abcdef
// def
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T;

  while (cin >> S >> T) {
    int ans = 0;
    int i = 0, j = 0;
    rep(k, 2) {
      rep(i, S.length()) {
        int tmp = 0;
        rep(j, S.length()) {
          if (i + j == S.length())
            break;
          if (S[i + j] == T[j])
            tmp++;
          else
            tmp = 0;
          ans = max(ans, tmp);
        }
        // dump(ans);
      }
      swap(S, T);
    }
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[4001][4001];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (true) {
    string S, T;
    cin >> S >> T;

    rep(i, S.length()) {
      rep(j, T.length()) {
        if (S[i] == T[j])
          dp[i + 1][j + 1] = dp[i][j] + 1;
        // else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        else
          dp[i + 1][j + 1] = dp[i][j + 1];
      }
    }
    /*
    rep(i, S.length() + 1) {rep(j, T.length() + 1)
        cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
    */
    /*
    rep(i, S.length() + 1) {
        cout << i << " ";
        rep(j, T.length() + 1) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */

    cout << dp[S.length()][T.length()] << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <math.h>
#include <string.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1001001001;
char A[4002], B[4002];
int DP[4002];

int main() {
  while (scanf("%s", A) != EOF) {
    scanf("%s", B);
    int ans = 0;
    rep(i, strlen(A)) {
      for (int j = strlen(B); j > -1; j--) {
        if (A[i] == B[j]) {
          if (i != 0 && j != 0) {
            DP[j] = DP[j - 1];
          } else
            DP[j] = 0;
          DP[j]++;
        } else {
          DP[j] = 0;
        }
        ans = max(ans, DP[j]);
      }
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <math.h>
#include <string.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1001001001;
char A[4002], B[4002];
int DP[4002];

int main() {
  while (1) {
    scanf("%s", A);
    scanf("%s", B);
    int ans = 0;
    rep(i, strlen(A)) {
      for (int j = strlen(B); j > -1; j--) {
        if (A[i] == B[j]) {
          if (i != 0 && j != 0) {
            DP[j] = DP[j - 1];
          } else
            DP[j] = 0;
          DP[j]++;
        } else {
          DP[j] = 0;
        }
        ans = max(ans, DP[j]);
      }
    }
    printf("%d\\n", ans);
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  string str1, str2;

  while (true) {

    cin >> str1;

    if (cin.eof()) {
      break;
    }

    cin >> str2;

    int ans, len;
    ans = 0;

    int s1, s2;
    s1 = str1.size();
    s2 = str2.size();

    for (int off_ = -s1; off_ < s2; off_++) {
      len = 0;
      for (int j = max(0, off_); j < min(s1 + off_, s2); j++) {
        if (str1[j - off_] == str2[j]) {
          len++;
        } else {
          len = 0;
        }
        if (ans < len) {
          ans = len;
        }
      }
    }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {

  string str1, str2, s;

  while (true) {

    cin >> str1;

    if (cin.eof()) {
      break;
    }

    cin >> str2;

    int ans = 0;

    for (int i = 0; i < str1.size(); i++) {
      for (int j = 0; j < str1.size() - i; j++) {
        if (ans > j) {
          continue;
        }
        s = str1.substr(i, j);
        if (str2.find(s, 0) != string::npos) {
          if (s.size() > ans) {
            ans = s.size();
          }
        }
      }
    }

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

#include <bits/stdc++.h>
using namespace std;
int dp[4001][4001];
int main() {
  string a, b;
  while (true) {
    cin >> a >> b;
    if (cin.eof())
      return 0;
    memset(dp, 0, sizeof(dp));
    int ans = 0;
    for (int i = 0; i < (int)a.size(); i++) {
      for (int j = 0; j < (int)b.size(); j++) {
        if (a[i] == b[j]) {
          if (i * j == 0)
            dp[i][j] = 1;
          else
            dp[i][j] = dp[i - 1][j - 1] + 1;
          ans = max(ans, dp[i][j]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  while (true) {
    cin >> a >> b;
    if (cin.eof())
      return 0;
    int ans = 0;
    for (int i = 0; i < (int)a.size(); i++) {
      for (int j = 0; j < (int)b.size(); j++) {
        int temp = 0;
        while (i + temp < (int)a.size() && j + temp < (int)b.size() &&
               a[i + temp] == b[j + temp])
          temp++;
        ans = max(ans, temp);
      }
    }
    cout << ans << endl;
  }
  return 0;
}