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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string a, b;
  while (cin >> a >> b) {
    int ans = 0;
    reverse(a.begin(), a.end());
    for (int i = 0; i < b.size(); ++i) {
      a += "0";
    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < a.size(); ++i) {
      int count = 0;
      for (int j = 0; j + i < a.size() && j < b.size(); ++j) {
        if (a[i + j] == b[j]) {
          ++count;
        } else {
          ans = max(ans, count);
          count = 0;
        }
      }
      ans = max(ans, count);
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int getlength(int, int, string &, string &);
int main() {
  string a, b;
  while (cin >> a >> b) {
    a.push_back('a');
    b.push_back('b');
    int ans = 0;
    for (int i = 0; i < a.size() - 1; ++i) {
      for (int j = 0; j < b.size() - 1; ++j) {
        ans = max(ans, getlength(i, j, a, b));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

int getlength(int ap, int bp, string &a, string &b) {
  int res = 0;
  while (a[ap + res] == b[bp + res]) {
    ++res;
  }
  return res;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
short dp[4001][4001] = {};
char str1[4005], str2[4005];
short ans = 0;
int main() {
  while (scanf("%s", str1) != EOF) {
    scanf("%s", str2);
    int a = strlen(str1), b = strlen(str2);
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
        if (str1[i] == str2[j]) {
          if (i == 0 || j == 0) {
            dp[i][j] = 1;
            ans = max(ans, dp[i][j]);
          } else {
            dp[i][j] = 1 + dp[i - 1][j - 1];
            ans = max(ans, dp[i][j]);
          }
        }
      }
    }
    printf("%d\\n", ans);
    ans = 0;
    memset(dp, 0, sizeof(dp));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
short dp[4001][4001] = {};
char str1[4005], str2[4005];
short ans = 0;
int main() {
  while (scanf("%s", str1) != EOF) {
    scanf("%s", str2);
    for (int i = 0; i < strlen(str1); i++) {
      for (int j = 0; j < strlen(str2); j++) {
        if (str1[i] == str2[j]) {
          if (i == 0 || j == 0) {
            dp[i][j] = 1;
            ans = max(ans, dp[i][j]);
          } else {
            dp[i][j] = 1 + dp[i - 1][j - 1];
            ans = max(ans, dp[i][j]);
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error


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

int dp[4001][4001];

int main() {
  string a, b;
  while (cin >> a >> b) {
    int ans = 0;
    for (int i = 0; i < a.length(); i++) {
      for (int j = 0; j < b.length(); j++) {
        if (a[i] == b[j])
          ans = max(dp[i + 1][j + 1] = dp[i][j] + 1, ans);
        else
          dp[i + 1][j + 1] = 0;
      }
    }

    cout << ans << endl;
  }
}

Error: WA

Fixed submission:


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

int dp[4000][4000];

int main() {
  string a, b;
  int ans = 0;
  while (cin >> a >> b) {
    for (int i = 0; i < a.length(); i++) {
      for (int j = 0; j < b.length(); j++) {
        if (a[i + 1] == b[j + 1])
          ans = max(dp[i + 1][j + 1] = dp[i][j] + 1, ans);
        else
          dp[i + 1][j + 1] = 0;
      }
    }

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

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

int dp[4001][4001];
int main() {

  string str1, str2;
  int ans;
  while (cin >> str1 >> str2) {
    ans = 0;
    // cout << str1 << endl << str2 << endl;
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= str1.size(); i++) {
      for (int j = 1; j <= str2.size(); j++) {
        if (str1[i - 1] == str2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          ans = max(ans, dp[i][j]);
        } else
          dp[i][j] = 0;
      }
    }
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

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

int dp[4000][4000];

int main() {

  string str1, str2;

  while (cin >> str1 >> str2) {

    memset(dp, 0, sizeof(dp));

    for (int i = 1; i <= str1.size(); i++) {
      for (int j = 1; j <= str2.size(); j++) {
        if (str1[i - 1] == str2[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
        } else
          dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
    cout << dp[str1.size()][str2.size()] << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

short dp[4002][4002];

int main() {
  string a, b;

  while (cin >> a >> b) {
    int n = a.length();
    int m = b.length();

    memset(dp, 0, sizeof(dp));
    short res = 0;

    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (a[i - 1] == b[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          res = max(res, dp[i][j]);
        }
      }
    }

    cout << res << endl;
  }
}

Error: MLE

Fixed submission:

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

int dp[4002][4002];

int main() {
  string a, b;

  while (cin >> a >> b) {
    int n = a.length();
    int m = b.length();

    memset(dp, 0, sizeof(dp));
    int res = 0;

    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (a[i - 1] == b[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          res = max(res, dp[i][j]);
        }
      }
    }

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

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

int main() {
  string s, t;
  static int dp[4001][4001] = {};
  while (cin >> s >> t) {
    for (int i = 0; i <= s.length(); i++) {
      for (int j = 0; j <= t.length(); j++)
        dp[i][j] = 0;
    }
    int ma = 0;
    for (int i = 0; i < s.length(); i++) {
      for (int j = 0; j < t.length(); j++) {
        if (s[i] == t[j])
          dp[i + 1][j + 1] = dp[i][j] + 1;
        ma = max(ma, dp[i + 1][j + 1]);
      }
    }
    cout << ma << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  string s, t;
  while (cin >> s >> t) {
    int ma = 0;
    int dp[4001][4001] = {};
    for (int i = 0; i < s.length(); i++) {
      for (int j = 0; j < t.length(); j++) {
        if (s[i] == t[j])
          dp[i + 1][j + 1] = dp[i][j] + 1;
        ma = max(ma, dp[i + 1][j + 1]);
      }
    }
    cout << ma << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <stdio.h>
#include <string.h>
#define max(i, j) (i < j ? j : i)
short dp[4001][4001];
int main(void) {
  char s[4001], t[4001];
  //	printf("%d\\n",4000*4000);
  while (scanf("%s", s) != EOF) {
    scanf("%s", t);
    //		dp[0][0]=s[0]==t[0];
    for (int i = 0; i < 4001; i++)
      dp[i][0] = dp[0][i] = 0;
    int sl = strlen(s), tl = strlen(t);
    int ans = 0;
    for (int i = 1; i <= sl; i++) {
      for (int j = 1; j <= tl; j++) {
        if (s[i - 1] == t[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          ans = max(ans, dp[i][j]);
        } else
          dp[i][j] = 0;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#define max(i, j) (i < j ? j : i)
int dp[4001][4001];
int main(void) {
  char s[4001], t[4001];
  //	printf("%d\\n",4000*4000);
  while (scanf("%s", s) != EOF) {
    scanf("%s", t);
    //		dp[0][0]=s[0]==t[0];
    for (int i = 0; i < 4001; i++)
      dp[i][0] = dp[0][i] = 0;
    int sl = strlen(s), tl = strlen(t);
    int ans = 0;
    for (int i = 1; i <= sl; i++) {
      for (int j = 1; j <= tl; j++) {
        if (s[i - 1] == t[j - 1]) {
          dp[i][j] = dp[i - 1][j - 1] + 1;
          ans = max(ans, dp[i][j]);
        } else
          dp[i][j] = 0;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
short cnt[4100][4100];
int main() {
  string str1, str2;
  while (cin >> str1) {
    cin >> str2;
    int len1 = str1.size();
    int len2 = str2.size();
    str1 = ' ' + str1;
    str2 = ' ' + str2;
    for (int i = 1; i <= len1; i++) {
      cnt[i][0] = 0;
    }
    for (int i = 1; i <= len2; i++) {
      cnt[0][i] = 0;
    }
    short ret = 0;
    for (int i = 1; i <= len1; i++) {
      for (int j = 1; j <= len2; j++) {
        if (str1[i] == str2[j]) {
          cnt[i][j] = cnt[i - 1][j - 1] + 1;
        } else {
          cnt[i][j] = 0;
        }
        ret = max(ret, cnt[i][j]);
      }
    }
    cout << ret << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int cnt[4100][4100];
int main() {
  string str1, str2;
  while (cin >> str1) {
    cin >> str2;
    int len1 = str1.size();
    int len2 = str2.size();
    str1 = ' ' + str1;
    str2 = ' ' + str2;
    for (int i = 1; i <= len1; i++) {
      cnt[i][0] = 0;
    }
    for (int i = 1; i <= len2; i++) {
      cnt[0][i] = 0;
    }
    int ret = 0;
    for (int i = 1; i <= len1; i++) {
      for (int j = 1; j <= len2; j++) {
        if (str1[i] == str2[j]) {
          cnt[i][j] = cnt[i - 1][j - 1] + 1;
        } else {
          cnt[i][j] = 0;
        }
        ret = max(ret, cnt[i][j]);
      }
    }
    cout << ret << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int DP[4001][4001];

int main() {
  string s, t;
  while (cin >> s >> t) {
    memset(DP, 0, sizeof(DP));
    int n = s.size(), m = t.size(), ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (s[i] == t[j]) {
          DP[i + 1][j + 1] = DP[i][j] + 1;
          ans = max(DP[i + 1][j + 1], ans);
        } else {
          DP[i + 1][j + 1] = 0;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

int DP[4096][4096];
int main() {
  string s, t;
  while (cin >> s >> t) {
    memset(DP, 0, sizeof(DP));
    int n = s.size(), m = t.size(), ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (s[i] == t[j]) {
          DP[i + 1][j + 1] = DP[i][j] + 1;
          ans = max(DP[i + 1][j + 1], ans);
        } 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>

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

int dp[4001];

int main(void) {
  string s, t;
  while (cin >> s >> t) {
    if (cin.eof())
      break;
    int n = s.size(), m = t.size();

    int ans = 0;
    rep(start, n) {
      rep(i, max(n, m)) {
        if (start + i >= n || i >= m)
          break;
        if (s[start + i] == t[i])
          dp[i + 1] = dp[i] + 1;
        else
          dp[i + 1] = 0;
        ans = max(ans, dp[i + 1]);
      }
    }

    rep(start, m) {
      rep(i, max(n, m)) {
        if (i >= n || i + start >= m)
          break;
        if (s[i] == t[i + start])
          dp[i + 1] = dp[i] + 1;
        else
          dp[i + 1] = 0;
        ans = max(ans, dp[i + 1]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

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

int dp[4001][4001];

int main(void) {
  string s, t;
  while (cin >> s >> t) {
    if (cin.eof())
      break;
    int n = s.size(), m = t.size();
    rep(i, n) rep(j, m) 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
        dp[i + 1][j + 1] = 0;
    }
    int ans = 0;
    rep(i, n + 1) rep(j, m + 1) ans = max(ans, dp[i][j]);
    cout << ans << endl;
  }
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dp[4010][4010];

int main() {
  string s, t;
  while (cin >> s >> t) {
    rep(i, 4010) rep(j, 4010) dp[i][j] = 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;
      }
    }
    int ans = 0;
    rep(i, s.size() + 1) rep(j, t.size() + 1) ans = max(ans, dp[i][j]);
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, e) for (int i = (s); i < (e); i++)
#define pb(n) push_back((n))
#define mp(n, m) make_pair((n), (m))
#define all(r) r.begin(), r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 10000000;

int main() {
  string s, t;
  while (cin >> s >> t) {
    if (s.size() > t.size())
      swap(s, t);
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      for (int j = max(1, ans); j < s.size() - i; j++) {
        if (t.find(s.substr(i, j)) != string::npos) {
          ans = j;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  string str, str2;
  vector<short int> array[4001];
  int i, j;

  for (i = 0; i < 4001; i++) {
    for (j = 0; j < 4001; j++) {
      array[i].push_back(0);
    }
  }

  for (; cin >> str;) {
    cin >> str2;
    int ans = 0;
    for (i = 1; i <= str.size(); i++) {
      for (j = 1; j <= str2.size(); j++) {
        array[i][j] = 0;
        if (str[i - 1] == str2[j - 1]) {
          array[i][j] = array[i - 1][j - 1] + 1;
        }
        if (ans < array[i][j])
          ans = array[i][j];
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string str, str2;

  for (; cin >> str;) {
    cin >> str2;
    int ans = 0;
    if (str.size() > str2.size()) {
      string a;
      a = str2;
      str2 = str;
      str = a;
    }

    for (int i = 0; i + ans < str.size(); i++) {
      for (int j = ans + 1; i + j <= str.size(); j++) {
        string se;
        se = str.substr(i, j);
        if (str2.find(se) != -1) {
          if (ans < se.size())
            ans = se.size();
        } else {
          break;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  string str, str2;
  int i, j;
  vector<short int> ss[4001];

  for (i = 0; i < 4000; i++)
    for (j = 0; j < 4000; j++)
      ss[i].push_back(0);

  for (; cin >> str;) {
    cin >> str2;

    int ans = 0;

    for (i = 0; i < str.size(); i++) {
      for (j = 0; j < str2.size(); j++) {
        ss[i][j] = 0;
        if (str[i] == str2[j] && i != 0 && j != 0)
          ss[i][j] = ss[i - 1][j - 1] + 1;
        else if (str[i] == str2[j])
          ss[i][j]++;

        if (ss[i][j] > ans)
          ans = ss[i][j];
      }
    }
    cout << ans << endl;
  }
}

Error: -11

Fixed submission:

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

using namespace std;

int main() {
  string str, str2;
  int i, j;

  for (; cin >> str;) {
    cin >> str2;

    short int ss[4001][4001];
    int ans = 0;

    for (i = 0; i < str.size(); i++) {
      for (j = 0; j < str2.size(); j++) {
        if (str[i] == str2[j] && i != 0 && j != 0)
          ss[i][j] = ss[i - 1][j - 1] + 1;

        else if (str[i] == str2[j])
          ss[i][j]++;

        if (ss[i][j] > ans)
          ans = ss[i][j];
      }
    }
    cout << ans << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define N 4001
int c[N][N];
int lcs(string s, string t) {
  int m = s.size();
  int n = t.size();
  int maxl = 0;
  s = ' ' + s;
  t = ' ' + t;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= n; j++)
      c[i][j] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (s[i] == t[j])
        c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = 0;
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

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

Error: -11

Fixed submission:

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

int main() {
  cout << "????§?" << endl;
  string s, t;
  while (cin >> s >> t) {
    s = " " + s;
    t = " " + t;
    int Len[4001][4001];
    for (int i = 0; i < s.size(); i++) {
      Len[i][0] = 0;
    }
    for (int i = 1; i <= s.size(); i++) {
      for (int j = 1; j <= t.size(); j++) {
        if (s[i] == t[j])
          Len[i][j] = 1 + Len[i - 1][j - 1];
        else
          Len[i][j] = 0;
      }
    }
    int an = 1;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < t.size(); j++) {
        an = max(an, Len[i][j]);
      }
    }
    if (an == 1)
      cout << 0 << endl;
    else
      cout << an << endl;
  }
  cout << "syuuryou" << endl;
  return 0;
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

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

string str1;
string str2;
int solve() {
  int count = 0;
  int m = 0;
  int limit1;
  int limit2;
  int limit;
  int i, j;
  limit1 = str1.size();
  limit2 = str2.size();
  for (i = 0; i < limit1 - 1; i++) {
    for (j = 0; j < i + 1; j++) {
      if (str1[limit1 - 1 - i + j] == str2[j]) {
        count++;
      } else {
        m = max(m, count);
        count = 0;
      }
    }
    m = max(m, count);
    count = 0;
  }
  count = 0;
  for (i = 0; i < limit2; i++) {
    limit = limit1 + i < limit2 ? limit1 : limit2 - i;
    for (j = 0; j < limit; j++) {
      if (str1[j] == str2[j + i]) {
        count++;
      } else {
        m = max(m, count);
        count = 0;
      }
    }
    m = max(m, count);
    count = 0;
  }
  return m;
}
int main() {
  string temp;
  while (cin >> str1 >> str2) {
    if (str1.size() > str2.size()) {
      swap(str1, str2);
    }
    cout << solve() << endl;
  }
}

Error: TLE

Fixed submission:

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

string str1;
string str2;
int solve() {
  int count = 0;
  int m = 0;
  int limit1;
  int limit2;
  int limit;
  limit1 = str1.size();
  limit2 = str2.size();
  for (int i = 0; i < limit2; i++) {
    limit = i + limit1 < limit2 ? i + limit1 : limit2;
    for (int j = i; j < limit; j++) {
      cout << str1[j - i] << str2[j];
      if (str1[j - i] == str2[j]) {
        count++;
      } else {
        m = max(m, count);
        count = 0;
      }
    }
  }
  return m;
}
int main() {
  string temp;
  while (cin >> str1 >> str2) {
    if (str1.size() > str2.size()) {
      temp = str1;
      str1 = str2;
      str2 = temp;
    }
    cout << solve() << endl;
  }
}
Problem p00451 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a, b) (abs((a) - (b)) < EPS)
int ans = 0;
int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    ans = 0;
    for (int i = 0; i < s1.size(); i++) {
      int cnt = 0;
      for (int j = 0; j < min(s1.size() - i, s2.size()); j++) {
        if (s2[j] == s1[j + i]) {
          cnt++;
          ans = max(ans, cnt);
        } else {
          cnt = 0;
        }
      }
    }
    for (int i = 0; i < s2.size(); i++) {
      int cnt = 0;
      for (int j = 0; j < min(s2.size() - i, s1.size()); j++) {
        if (s1[j] == s2[j + i]) {
          cnt++;
          ans = max(ans, cnt);
        } else {
          cnt = 0;
        }
      }
    }
    cout << ans << endl;
    s1.clear();
    s2.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a, b) (abs((a) - (b)) < EPS)
int ans = 0;
int cal(string s1, string s2, int s, int p) {
  int cnt = 0;
  for (int i = p; i < s2.size(); i++) {
    if (s1[i + s] == s2[i])
      cnt++;
    else
      break;
  }
  return cnt;
}
int main() {
  while (1) {
    string s1, s2;
    cin >> s1;
    if (cin.eof())
      break;
    cin >> s2;
    ans = 0;
    for (int i = 0; i < s1.size(); i++) {
      for (int j = 0; j < s1.size() - i; j++) {
        if (s2[j] == s1[j + i]) {
          ans = max(ans, cal(s1, s2, i, j));
        }
      }
    }
    for (int i = 0; i < s2.size(); i++) {
      for (int j = 0; j < s2.size() - i; j++) {
        if (s1[j] == s2[j + i]) {
          ans = max(ans, cal(s2, s1, i, j));
        }
      }
    }
    cout << ans << endl;
    s1.clear();
    s2.clear();
  }
  return 0;
}