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

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

void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i) {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
                   const vector<string> &cnrvsStrY) {
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i) {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

    vvnLcsDP.clear();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

Error: 0

Fixed submission:

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

void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i) {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
                   const vector<string> &cnrvsStrY) {
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i) {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

    vvnLcsDP.shrink_to_fit();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}
Problem p02235 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int c[4001][4001]{};
signed main() {
  int n;
  scanf("%d", &n);
  char a[5000];
  char b[5000];
  for (int m = 0; m < n; m++) {
    scanf("%s%s", a, b);
    int d, e;
    d = strlen(a);
    e = strlen(b);
    for (int t = 0; t <= d; t++) {
      for (int w = 0; w <= d; w++)
        c[t][w] = 0;
    }
    for (int x = 0; x < d; x++) {
      for (int y = 0; y < e; y++) {
        if (a[x] == b[y])
          c[x + 1][y + 1] = c[x][y] + 1;
        else
          c[x + 1][y + 1] = max(c[x][y + 1], c[x + 1][y]);
      }
    }
    printf("%d\\n", c[d][e]);
  }
}

Error: TLE

Fixed submission:

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

int dp[1001][1001];
int main() {
  int b;
  scanf("%d", &b);
  char e[1001];
  char f[1001];
  for (int c = 0; c < b; c++) {
    scanf("%s%s", e, f);
    for (int g = 0; g <= strlen(e); g++) {
      for (int h = 0; h <= strlen(f); h++) {
        dp[g][h] = 0;
      }
    }
    for (int g = 0; g < strlen(e); g++) {
      for (int h = 0; h < strlen(f); h++) {
        if (e[g] == f[h]) {
          dp[g + 1][h + 1] = dp[g][h] + 1;
        } else {
          if (dp[g][h + 1] > dp[g + 1][h])
            dp[g + 1][h + 1] = dp[g][h + 1];
          else
            dp[g + 1][h + 1] = dp[g + 1][h];
        }
      }
    }
    printf("%d\\n", dp[strlen(e)][strlen(f)]);
  }
}
Problem p02235 (C++) — buggy submission, verdict: Runtime Error

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

static const int N = 1000;

int lcs(string X, string Y) {
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 0; i <= m; i++)
    c[i][0] = 0;
  for (int j = 0; j <= n; j++)
    c[0][j] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      } else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main() {
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {

  string str1;
  string str2;
  int n, s1, s2;
  int c[1001][1001] = {{}};
  int max = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {

    cin >> str1 >> str2;

    str1 = ' ' + str1;
    str2 = ' ' + str2;

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

    for (int j = 1; j < s1; j++) {
      for (int k = 1; k < s2; k++) {
        if (str1[j] == str2[k]) {
          c[j][k] = c[j - 1][k - 1] + 1;
          if (c[j][k] > max)
            max = c[j][k];
        } else if (c[j - 1][k] > c[j][k - 1]) {
          c[j][k] = c[j - 1][k];
        } else {
          c[j][k] = c[j][k - 1];
        }
      }
    }

    cout << max << endl;

    max = 0;

    for (int j = 0; j <= s1; j++) {
      for (int k = 0; k <= s2; k++) {
        c[j][k] = 0;
      }
    }
  }
}
Problem p02235 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int q, t1, t2;
  string s1, s2;
  const int maxS = 1000;
  int m[maxS][maxS];

  cin >> q;

  for (int i = 0; i < q; i++) {

    for (int i = 0; i < maxS; i++)
      for (int j = 0; j < maxS; j++)
        m[i][j] = 0;

    cin >> s1 >> s2;

    t1 = s1.size() - 1;
    t2 = s2.size() - 1;

    if (s1[0] == s2[0])
      m[0][0] = 1;

    for (int i = 0; i < t1; i++) {
      int f = 0;
      if (s1[i + 1] == s2[0])
        f = 1;
      m[i + 1][0] = max(m[i][0], f);
    }

    for (int j = 0; j < t2; j++) {
      int f = 0;
      if (s2[j + 1] == s1[0])
        f = 1;
      m[0][j + 1] = max(m[0][j], f);
    }

    for (int i = 0; i < t1; i++) {
      for (int j = 0; j < t2; j++) {
        if (s1[i + 1] == s2[j + 1])
          m[i + 1][j + 1] = m[i][j] + 1;
        else
          m[i + 1][j + 1] = max(m[i][j + 1], m[i + 1][j]);
      }
    }

    cout << m[t1][t2] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int q, t1, t2;
  string s1, s2;
  const int maxS = 10;
  int m[maxS][maxS];

  cin >> q;

  for (int i = 0; i < q; i++) {

    for (int i = 0; i < maxS; i++)
      for (int j = 0; j < maxS; j++)
        m[i][j] = 0;

    cin >> s1 >> s2;

    t1 = s1.size() - 1;
    t2 = s2.size() - 1;

    if (s1[0] == s2[0])
      m[0][0] = 1;

    for (int i = 0; i < t1; i++) {
      int f = 0;
      if (s1[i + 1] == s2[0])
        f = 1;
      m[i + 1][0] = max(m[i][0], f);
    }

    for (int j = 0; j < t2; j++) {
      int f = 0;
      if (s2[j + 1] == s1[0])
        f = 1;
      m[0][j + 1] = max(m[0][j], f);
    }

    for (int i = 0; i < t1; i++) {
      for (int j = 0; j < t2; j++) {
        if (s1[i + 1] == s2[j + 1])
          m[i + 1][j + 1] = m[i][j] + 1;
        else
          m[i + 1][j + 1] = max(m[i][j + 1], m[i + 1][j]);
      }
    }

    cout << m[t1][t2] << endl;
  }
  return 0;
}
Problem p02235 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int dp[1001][1001];

int lcs(std::string X, std::string Y) {
  int m, n, i, j;
  m = X.length();
  n = Y.length();
  for (i = 0; i < std::max(m, n) + 1; i++) {
    dp[i][0] = 0;
    dp[0][j] = 0;
  }

  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (X[i] == Y[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = std::max(dp[i][j + 1], dp[i + 1][j]);
      }
    }
  }
  return dp[m][n];
}
int main(void) {
  int i, q, n, m;
  std::string str1, str2;
  std::cin >> q;
  for (i = 0; i < q; i++) {
    std::cin >> str1;
    std::cin >> str2;
    std::cout << lcs(str1, str2) << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int dp[1000 + 1][1000 + 1];

int lcsSub(std::string X, std::string Y, int i, int j) {
  if (i == -1 || j == -1) {
    return 0;
  } else {
    if (X[i] == Y[j]) {
      if (dp[i][j] < 0) {
        dp[i][j] = lcsSub(X, Y, i - 1, j - 1);
      }
      return dp[i][j] + 1;
    } else {
      int up, left;
      if (dp[i + 1][j] < 0) {
        dp[i + 1][j] = lcsSub(X, Y, i, j - 1);
      }
      left = dp[i + 1][j];
      if (dp[i][j + 1] < 0) {
        dp[i][j + 1] = lcsSub(X, Y, i - 1, j);
      }
      up = dp[i][j + 1];

      return std::max(up, left);
    }
  }
}

int lcs(std::string X, std::string Y) {
  int m, n, i, j;
  m = X.length();
  n = Y.length();
  for (i = 0; i < m + 1; i++) {
    for (j = 0; j < n + 1; j++) {
      dp[i][j] = -1;
    }
  }
  return lcsSub(X, Y, m - 1, n - 1);
}
int main(void) {
  int i, q, n, m;
  std::string str1, str2;
  std::cin >> q;
  for (i = 0; i < q; i++) {
    std::cin >> str1;
    std::cin >> str2;
    std::cout << lcs(str1, str2) << std::endl;
  }
  return 0;
}
Problem p02235 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string s1, s2;
int memo[1001][1001];

int solve(int l1, int l2) {
  if (l1 < 0 or l2 < 0)
    return 0;
  if (memo[l1][l2] >= 0)
    return memo[l1][l2];
  // cout << s1[l1] << s2[l2] << endl;
  if (s1[l1] == s2[l2]) {
    return memo[l1][l2] = solve(l1 - 1, l2 - 1) + 1;
  }
  return memo[l1][l2] = max(solve(l1, l2 - 1), solve(l1 - 1, l2));
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    fill(memo[0], memo[1001], -1);
    cin >> s1;
    cin >> s2;
    cout << solve(s1.length(), s2.length()) - 1 << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string s1, s2;
int memo[100][100];

int solve(int l1, int l2) {
  if (l1 < 0 or l2 < 0)
    return 0;
  if (memo[l1][l2] >= 0)
    return memo[l1][l2];
  // cout << s1[l1] << s2[l2] << endl;
  if (s1[l1] == s2[l2]) {
    return memo[l1][l2] = solve(l1 - 1, l2 - 1) + 1;
  }
  return memo[l1][l2] = max(solve(l1, l2 - 1), solve(l1 - 1, l2));
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    fill(memo[0], memo[100], -1);
    cin >> s1;
    cin >> s2;
    cout << solve(s1.length(), s2.length()) - 1 << endl;
  }
}
Problem p02235 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int q;
int len[1005][1005];

int common(string a, string b, int m, int n) {
  int i, j;
  for (i = 0; i <= m; i++)
    len[i][0] = 0;
  for (i = 0; i <= n; i++)
    len[0][i] = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (a[i] == b[j])
        len[i + 1][j + 1] = len[i][j] + 1;
      else
        len[i + 1][j + 1] = max(len[i + 1][j], len[i][j + 1]);
    }
  }
  return len[m][n];
}

int main() {
  cin >> q;
  int i;
  for (i = 0; i < q; i++) {
    string a, b;
    cin >> a >> b;
    int m = a.length();
    int n = b.length();
    cout << common(a, b, m, n) << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

int q;
int **len;
int common(string a, string b, int m, int n) {
  if (m == 0 || n == 0) {
    return 0;
  }
  if (a[m - 1] == b[n - 1]) {
    if (m > 1 && n > 1) {
      if (len[m - 2][n - 2] != -1)
        len[m - 1][n - 1] = len[m - 2][n - 2] + 1;
      else
        len[m - 1][n - 1] =
            common(a.substr(0, m - 1), b.substr(0, n - 1), m - 1, n - 1) + 1;
    } else {
      len[m - 1][n - 1] = 1;
    }
  } else {
    int l1, l2;
    //?±?l1
    if (n > 1) {
      if (len[m - 1][n - 2] != -1)
        l1 = len[m - 1][n - 2];
      else
        l1 = len[m - 1][n - 2] = common(a, b.substr(0, n - 1), m, n - 1);
    } else
      l1 = 0;
    if (m > 1) {
      if (len[m - 2][n - 1] != -1)
        l2 = len[m - 2][n - 1];
      else
        l2 = len[m - 2][n - 1] = common(a.substr(0, m - 1), b, m - 1, n);
    } else
      l2 = 0;

    len[m - 1][n - 1] = max(l1, l2);
  }
  return len[m - 1][n - 1];
}

int main() {
  cin >> q;
  int i;
  for (i = 0; i < q; i++) {
    string a, b;
    cin >> a >> b;
    int m = a.length();
    int n = b.length();
    len = new int *[m];
    int j;
    for (j = 0; j < m; j++) {
      len[j] = new int[n];
      memset(len[j], -1, n * sizeof(int));
    }
    cout << common(a, b, m, n) << endl;
  }
  return 0;
}

// int main(){
//     int **p=new int*[5];
//     p[1]=new int[5];
//     memset(p[1],-1,5*sizeof(int));
//     cout<<p[1][3]<<" "<<p[0][1];
// }
Problem p02235 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

string s1, s2;
int l[1010][1010];
bool flag[1010][1010];

int L(int i, int j) {
  // cout<<i<<" "<<j<<endl;
  if (i < 0 || j < 0) {
    return 0;
  } else if (s1.at(i) == s2.at(j)) {
    if (!flag[i][j]) {
      l[i][j] = 1 + L(i - 1, j - 1);
      flag[i][j] = true;
    }
    return l[i][j];
  } else {
    if (!flag[i][j]) {
      int a = L(i, j - 1);
      int b = L(i - 1, j);
      l[i][j] = a > b ? a : b;
      flag[i][j] = true;
    }
    return l[i][j];
  }
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> s1 >> s2;
    for (int j = 0; j < 1010; j++) {
      for (int k = 0; k < 1010; k++) {
        flag[j][k] = false;
      }
    }

    cout << L(s1.size() - 1, s2.size() - 1) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

string s1, s2;

int L(int i, int j) {
  if (i < 0 || j < 0)
    return 0;
  else if (s1.at(i) == s2.at(j))
    return 1 + L(i - 1, j - 1);
  else {
    int a = L(i, j - 1);
    int b = L(i - 1, j);
    return a > b ? a : b;
  }
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> s1 >> s2;
    cout << L(s1.size() - 1, s2.size() - 1) << endl;
  }
}
Problem p02235 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
  int num;
  cin >> num;
  rep(k, 0, num) {
    string s1, s2;
    cin >> s1 >> s2;

    int dp
        [1001]
        [1001]; // s1???i??????????????§???s2???j??????????????§??§???LCS????±???????????????????
    int n = s1.length();
    int m = s2.length();
    rep(i, 0, m + 1) dp[0][i] = 0;

    rep(i, 0, n) {
      rep(j, 0, m) {
        if (s1[i] == s2[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]);
      }
    }
    cout << dp[n][m] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
  int num;
  cin >> num;
  rep(k, 0, num) {
    string s1, s2;
    cin >> s1 >> s2;

    int dp
        [101]
        [101]; // s1???i??????????????§???s2???j??????????????§??§???LCS????±???????????????????
    int n = s1.length();
    int m = s2.length();
    rep(i, 0, m + 1) dp[0][i] = 0;

    rep(i, 0, n) {
      rep(j, 0, m) {
        if (s1[i] == s2[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]);
      }
    }
    cout << dp[n][m] << endl;
  }
  return 0;
}
Problem p02235 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  string st1, st2;
  int q, val[1001][1001];

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> st1;
    cin >> st2;

    for (int j = 0; j <= st1.length(); j++) {
      for (int k = 0; k <= st2.length(); k++) {

        if (j == 0 || k == 0)
          val[j][k] = 0;
        else {
          if (val[j - 1][k] == min(st1.length(), st2.length())) {
            val[j][k] = st1.length();
          } else {

            if (st1[j - 1] == st2[k - 1]) {
              val[j][k] = val[j - 1][k - 1] + 1;
            } else {
              val[j][k] = max(val[j - 1][k], val[j][k - 1]);
            }
          }
        }
      }
    }

    /*
      for(int j=0; j<=st1.length(); j++){
      for(int k=0; k<=st2.length(); k++){
      cout << val[j][k] << " ";
      }
      cout << "\\n";
      }
    */

    cout << val[st1.length()][st2.length()] << "\\n";
  }

  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  string st1, st2;
  int q, val[151][151];

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> st1;
    cin >> st2;

    for (int j = 0; j <= st1.length(); j++) {
      for (int k = 0; k <= st2.length(); k++) {

        if (j == 0 || k == 0)
          val[j][k] = 0;
        else {
          if (val[j - 1][k] == min(st1.length(), st2.length())) {
            val[j][k] = st1.length();
          } else {

            if (st1[j - 1] == st2[k - 1]) {
              val[j][k] = val[j - 1][k - 1] + 1;
            } else {
              val[j][k] = max(val[j - 1][k], val[j][k - 1]);
            }
          }
        }
      }
    }

    /*
      for(int j=0; j<=st1.length(); j++){
      for(int k=0; k<=st2.length(); k++){
      cout << val[j][k] << " ";
      }
      cout << "\\n";
      }
    */

    cout << val[st1.length()][st2.length()] << "\\n";
  }

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

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

int main() {
  int setN;
  cin >> setN;
  string A, B;

  for (int i = 0; i < setN; i++) {
    cin >> A;
    cin >> B;
    int L[2000][2000] = {};

    for (int j = 1; j < A.length() + 1; j++) {
      for (int l = 1; l < B.length() + 1; l++) {
        if (A[j - 1] == B[l - 1]) {
          L[j][l] = 1 + L[j - 1][l - 1];

        } else {
          L[j][l] = max(L[j - 1][l], L[j][l - 1]);
        }
      }
    }
    /*
    for(int j=0;j<A.length()+1;j++) {
            cout << endl;
            for(int l=0;l<B.length()+1;l++) {
                    cout << L[j][l] << " ";

            }
    }
    */

    cout << L[A.length()][B.length()] << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int setN;
  cin >> setN;
  string A, B;

  for (int i = 0; i < setN; i++) {
    cin >> A;
    cin >> B;
    int L[1000][1000] = {};

    for (int j = 1; j < A.length() + 1; j++) {
      for (int l = 1; l < B.length() + 1; l++) {
        if (A[j - 1] == B[l - 1]) {
          L[j][l] = 1 + L[j - 1][l - 1];

        } else {
          L[j][l] = max(L[j - 1][l], L[j][l - 1]);
        }
      }
    }
    /*
    for(int j=0;j<A.length()+1;j++) {
            cout << endl;
            for(int l=0;l<B.length()+1;l++) {
                    cout << L[j][l] << " ";

            }
    }
    */

    cout << L[A.length()][B.length()] << endl;
  }
}
Problem p02235 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#define MAX 1001
using namespace std;

string x, y;

int c[MAX][MAX];
int lcs(int m, int n);

int main() {
  int i, q, n, m;
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> x >> y;
    cout << lcs(x.length(), y.length()) << endl;
  }
  return 0;
}

int lcs(int m, int n) {
  int i, j, maxl = 0;
  c[0][0] = 0;
  for (i = 1; i <= m; i++)
    c[i][0] = 0;
  for (j = 1; j <= n; j++)
    c[0][j] = 0;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      if (x[i - 1] == y[j - 1])
        c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i][j - 1], c[i - 1][j]);
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#define MAX 10
using namespace std;

string x, y;

int lcs(int m, int n);

int main() {
  int i, q, n, m;
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> x >> y;
    cout << lcs(x.length(), y.length()) << endl;
  }
  return 0;
}

int lcs(int m, int n) {
  int i, j, maxl = 0, c[MAX][MAX];
  c[0][0] = 0;
  for (i = 1; i <= m; i++)
    c[i][0] = 0;
  for (j = 1; j <= n; j++)
    c[0][j] = 0;
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      if (x[i - 1] == y[j - 1])
        c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i][j - 1], c[i - 1][j]);
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}