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

#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ar = array<ull, 26>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, a, n) for (int i = a; i < n; i++)
int main() {
  string s1, s2;
  ar ht;
  ht[0] = 1;
  rep(i, 25) ht[i + 1] = ht[i] * 10007;

  while (cin >> s1 >> s2) {
    if (s1.size() > s2.size())
      swap(s1, s2);
    int n1 = s1.size(), n2 = s2.size();
    unordered_set<ull> list1;
    vector<ull> p1, p2;
    for (auto c : s1)
      p1.push_back(ht[c - 'a']);
    for (auto c : s2)
      p2.push_back(ht[c - 'a']);

    for (int l = n1; l >= 1; l--) {
      list1.clear();
      ull tmp = 0;
      rep(i, n1) {
        tmp += p1[i];
        if (i >= l)
          tmp -= p1[i - l];
        if (i >= l - 1)
          list1.insert(tmp);
      }
      tmp = 0;
      rep(i, n2) {
        tmp += p2[i];
        if (i >= l)
          tmp -= p2[i - l];
        if (i >= l - 1) {
          if (list1.find(tmp) != list1.end()) {
            cout << l << endl;
            goto end;
          }
        }
      }
    }
    cout << 0 << endl;
  end:;
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ar = array<ull, 26>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, a, n) for (int i = a; i < n; i++)
int main() {
  string s1, s2;
  ar ht;
  ht[0] = 1;
  rep(i, 25) ht[i + 1] = ht[i] * 10007;

  while (cin >> s1 >> s2) {
    if (s1.size() > s2.size())
      swap(s1, s2);
    int n1 = s1.size(), n2 = s2.size();
    array<unordered_set<ull>, 4001> list1;
    rep(i, n1) {
      ull tmp = 0;
      range(j, i, n1) {
        tmp += ht[s1[j] - 'a'];
        list1[j - i + 1].insert(tmp);
      }
    }

    for (int l = n1; l >= 1; l--) {
      ull tmp = 0;
      rep(i, n2) {
        tmp += ht[s2[i] - 'a'];
        if (i >= l)
          tmp -= ht[s2[i - l] - 'a'];
        if (i >= l - 1) {
          if (list1[l].find(tmp) != list1[l].end()) {
            cout << l << endl;
            goto end;
          }
        }
      }
    }
    cout << 0 << endl;
  end:;
  }
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

const int inf = 1 << 29;

array<int, 26> sum[2][4010];

typedef unsigned long long ull;

const ull B = 1 ^ 9 + 7;

int main() {

  string S[2];
  int N[2];

  rep(i, 2) {
    cin >> S[i];
    N[i] = S[i].size();
  }

  rep(k, 2) rep(i, N[k]) {
    rep(j, 26) sum[k][i + 1][j] += sum[k][i][j];
    sum[k][i + 1][S[k][i] - 'a']++;
  }

  int ans = 0;

  REP(length, 1, min(N[1], N[0]) + 1) {
    set<ull> st;
    rep(i, N[1] - length + 1) {
      auto subsum = sum[1][i + length];
      rep(k, 26) subsum[k] -= sum[1][i][k];
      ull hash = 0;
      rep(k, 26) hash = hash * B + subsum[k];
      st.insert(hash);
    }

    rep(i, N[0]) {
      auto subsum = sum[0][i + length];
      rep(k, 26) subsum[k] -= sum[0][i][k];
      ull hash = 0;
      rep(k, 26) hash = hash * B + subsum[k];
      if (st.count(hash)) {
        ans = max(ans, length);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Error: MLE

Fixed submission:

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

const int inf = 1 << 29;

array<int, 26> sum[2][4010];

typedef unsigned long long ull;

const ull B = 1 ^ 9 + 7;

int main() {

  string S[2];
  int N[2];

  rep(i, 2) {
    cin >> S[i];
    N[i] = S[i].size();
  }

  rep(k, 2) rep(i, N[k]) {
    rep(j, 26) sum[k][i + 1][j] += sum[k][i][j];
    sum[k][i + 1][S[k][i] - 'a']++;
  }

  unordered_set<ull> st;

  rep(i, N[1]) REP(j, i + 1, N[1] + 1) {
    auto subsum = sum[1][j];
    rep(k, 26) subsum[k] -= sum[1][i][k];
    ull hash = 0;
    rep(i, 26) { hash = hash * B + subsum[i]; }
    st.insert(hash);
  }

  int ans = 0;

  rep(i, N[0]) REP(j, i + 1, N[0] + 1) {
    auto subsum = sum[0][j];
    rep(k, 26) subsum[k] -= sum[0][i][k];
    ull hash = 0;
    rep(k, 26) hash = hash * B + subsum[k];
    if (st.count(hash)) {
      ans = max(ans, j - i);
    }
    /*
    int SN = j - i;
    rep(k, N[1] - SN + 1) {
      bool ok = 1;
      for(int l = 0; l<26; l++) {
        ok &= sum[0][j][l] - sum[0][i][l] == sum[1][k + SN][l] - sum[1][k][l];
      }
      if(ok) {
        ans = max(ans, SN);
      }
    }
    */
  }

  cout << ans << endl;

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

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

int main() {
  string s, t;
  cin >> s >> t;

  int S = s.size(), T = t.size();

  int ans = 0;
  for (int L = min(S, T); L >= 1; --L) {
    set<vector<int>> h;

    vector<int> ct(26, 0);
    rep(i, L)++ ct[t[i] - 'a'];

    h.insert(ct);
    for (int i = 1; i <= T - L; ++i) {
      --ct[t[i - 1] - 'a'];
      ++ct[t[i - 1 + L] - 'a'];
      h.insert(ct);
    }

    bool found = false;

    ct = vector<int>(26, 0);
    rep(i, L)++ ct[s[i] - 'a'];

    if (h.find(ct) != h.end()) {
      ans = L;
      break;
    }

    for (int i = 1; i <= S - L; ++i) {
      --ct[s[i - 1] - 'a'];
      ++ct[s[i - 1 + L] - 'a'];
      if (h.find(ct) != h.end()) {
        found = true;
        ans = L;
        break;
      }
    }

    if (found)
      break;
  }

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

Error: TLE

Fixed submission:

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

int ss[26][4001] = {0}, st[26][4001] = {0};

int main() {
  string s, t;
  cin >> s >> t;

  int S = s.size(), T = t.size();
  rep(i, S) ss[s[i] - 'a'][i + 1]++;
  rep(i, T) st[t[i] - 'a'][i + 1]++;

  rep(i, 26) {
    rep(j, S) ss[i][j + 1] += ss[i][j];
    rep(j, T) st[i][j + 1] += st[i][j];
  }

  // rep(i,8)
  // {
  //     rep(j,S) printf("ss[%d][%d]=%d\\n",i,j,ss[i][j]);
  //     rep(j,T) printf("st[%d][%d]=%d\\n",i,j,st[i][j]);
  // }

  int ans = 0;
  rep(i, S) rep(j, T) {
    int max_len = min(S - i, T - j);
    // printf("i=%d,j=%d, max=%d\\n", i,j,max_len);
    for (int k = max_len; k > ans; --k) {
      int ii = i + k, jj = j + k;

      bool valid = true;
      rep(a, 26) {
        if (ss[a][ii] - ss[a][i] != st[a][jj] - st[a][j]) {
          valid = false;
          break;
        }
      }

      if (valid) {
        // printf("i=%d, j=%d ,k=%d\\n", i,j,k);
        ans = k;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

using vi = vector<int>;

int main() {
  string s, t;
  cin >> s >> t;
  int S = s.size(), T = t.size();

  int ans = 0;
  for (int i = 1; i <= min(S, T); ++i) {
    set<vi> x;

    vi ct(26);
    rep(j, i)++ ct[s[j] - 'a'];
    x.insert(ct);

    for (int j = i; j < S; ++j) {
      --ct[s[j - i] - 'a'];
      ++ct[s[j] - 'a'];
      x.insert(ct);
    }

    ct = vi(26);
    rep(j, i)++ ct[t[j] - 'a'];
    if (x.count(ct))
      ans = max(ans, i);

    for (int j = i; j < T; ++j) {
      --ct[t[j - i] - 'a'];
      ++ct[t[j] - 'a'];
      if (x.count(ct))
        ans = max(ans, i);
    }
  }
  cout << ans << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

using vi = vector<int>;

int main() {
  string s, t;
  cin >> s >> t;
  int S = s.size(), T = t.size();

  set<vi> x;
  for (int i = 1; i <= S; ++i) {
    vi ct(26);
    rep(j, i)++ ct[s[j] - 'a'];
    x.insert(ct);

    for (int j = i; j < S; ++j) {
      --ct[s[j - i] - 'a'];
      ++ct[s[j] - 'a'];
      x.insert(ct);
    }
  }

  int ans = 0;
  for (int i = 1; i <= T; ++i) {
    vi ct(26);
    rep(j, i)++ ct[t[j] - 'a'];
    if (x.count(ct))
      ans = max(ans, i);

    for (int j = i; j < T; ++j) {
      --ct[t[j - i] - 'a'];
      ++ct[t[j] - 'a'];
      if (x.count(ct))
        ans = max(ans, i);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef long long ll;
string s1, s2;

unordered_set<ll> S;

ll B = 107097077;
ll getHash(const vector<int> &v) {
  ll x = 0;
  for (int i = 0; i < 26; i++)
    x = x * B + v[i];
  return x;
}

vector<int> v[4444], w[4444];

int main() {
  cin >> s1 >> s2;
  int n = max(s1.size(), s2.size());
  for (int i = 0; i < n; i++)
    v[i] = w[i] = vector<int>(26, 0);
  int res = 0;
  for (int k = 0; k < n; k++) {
    S.clear();
    for (int i = 0; i < s1.size(); i++) {
      int j = i + k;
      if (j >= s1.size())
        continue;
      v[i][s1[j] - 'a']++;
      S.insert(getHash(v[i]));
    }
    for (int i = 0; i < s2.size(); i++) {
      int j = i + k;
      if (j >= s2.size())
        continue;
      w[i][s2[j] - 'a']++;
      if (S.count(getHash(w[i])))
        res = k + 1;
    }
  }

  cout << res << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

typedef unsigned int ll;
string s1, s2;

unordered_set<ll> S;

ll B = 107097077;
ll getHash(const vector<int> &v) {
  ll x = 0;
  for (int i = 0; i < 26; i++)
    x = x * B + v[i];
  return x;
}

int main() {
  cin >> s1 >> s2;

  for (int i = 0; i < s1.size(); i++) {
    vector<int> m(26, 0);
    for (int j = i; j < s1.size(); j++) {
      m[s1[j] - 'a']++;
      S.insert(getHash(m));
    }
  }

  int res = 0;
  for (int i = 0; i < s2.size(); i++) {
    vector<int> m(26, 0);
    for (int j = i; j < s2.size(); j++) {
      m[s2[j] - 'a']++;
      if (S.count(getHash(m)))
        res = max(res, j - i + 1);
    }
  }
  cout << res << endl;
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Time Limit Exceeded

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

signed main() {
  string a, b;
  cin >> a >> b;
  int n = a.size(), m = b.size();

  vector<vector<int>> suma(n + 1, vector<int>(26));
  vector<vector<int>> sumb(m + 1, vector<int>(26));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (a[i] - 'a' == j)
        suma[i + 1][j]++;
      suma[i + 1][j] += suma[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) {
      if (b[i] - 'a' == j)
        sumb[i + 1][j]++;
      sumb[i + 1][j] += sumb[i][j];
    }
  }

  for (int len = min(n, m); len >= 0; len--) {
    set<vector<int>> st;
    for (int i = 0; i < n; i++) {
      if (i + len > n)
        break;
      vector<int> v(26);
      for (int k = 0; k < 26; k++) {
        v[k] = suma[i + len][k] - suma[i][k];
      }
      st.emplace(v);
    }
    for (int i = 0; i < m; i++) {
      if (i + len > m)
        break;
      vector<int> v(26);
      for (int k = 0; k < 26; k++) {
        v[k] = sumb[i + len][k] - sumb[i][k];
      }
      if (st.count(v)) {
        cout << len << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

signed main() {
  string a, b;
  cin >> a >> b;
  int n = a.size(), m = b.size();

  vector<vector<int>> suma(n + 1, vector<int>(26));
  vector<vector<int>> sumb(m + 1, vector<int>(26));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (a[i] - 'a' == j)
        suma[i + 1][j]++;
      suma[i + 1][j] += suma[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) {
      if (b[i] - 'a' == j)
        sumb[i + 1][j]++;
      sumb[i + 1][j] += sumb[i][j];
    }
  }

  for (int len = min(n, m); len >= 0; len--) {
    for (int i = 0; i < n; i++) {
      if (i + len > n)
        break;
      for (int j = 0; j < m; j++) {
        if (j + len > m)
          break;
        bool ok = true;
        for (int k = 0; k < 26; k++) {
          if (suma[i + len][k] - suma[i][k] != sumb[j + len][k] - sumb[j][k]) {
            ok = false;
          }
        }
        if (ok) {
          cout << len << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

const int alph = 26;
int main() {
  string s, t;
  cin >> s >> t;
  if (s.length() > t.length())
    swap(s, t);
  for (int len = s.length(); len >= 1; len--) {
    vector<int> vec(alph);
    for (int i = 0; i < len - 1; i++) {
      vec[s[i] - 'a']++;
    }

    map<vector<int>, int> mp;
    for (int i = len - 1; i < (int)s.length(); i++) {
      vec[s[i] - 'a']++;
      mp[vec]++;
      vec[s[i - len + 1] - 'a']--;
    }

    vec = vector<int>(alph);
    for (int i = 0; i < len - 1; i++) {
      vec[t[i] - 'a']++;
    }
    for (int i = len - 1; i < (int)t.length(); i++) {
      vec[t[i] - 'a']++;
      if (mp.count(vec)) {
        cout << len << endl;
        return 0;
      }
      vec[t[i - len + 1] - 'a']--;
    }
  }
  cout << 0 << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const int alph = 26;
set<vector<int>> S;
void make_set(string s, int mode) {
  int N = s.length();
  int cnt[4010][alph] = {};
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < alph; j++) {
      cnt[i + 1][j] += cnt[i][j];
    }
    cnt[i + 1][s[i] - 'a']++;
  }

  int ans = 0;
  for (int l = 0; l < N; l++) {
    for (int r = l + 1; r <= N; r++) {
      vector<int> vec;
      int sum = 0;
      for (int k = 0; k < alph; k++) {
        int val = cnt[r][k] - cnt[l][k];
        vec.push_back(val);
        sum += val;
      }
      if (mode == 0)
        S.insert(vec);
      else {
        if (S.count(vec)) {
          ans = max(ans, sum);
        }
      }
    }
  }
  if (mode == 1) {
    cout << ans << endl;
  }
}

int main() {
  string s, t;
  cin >> s >> t;
  if (s.length() > t.length())
    swap(s, t);
  make_set(s, 0);
  make_set(t, 1);
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

typedef pair<int, int> P;

const int mod[2] = {1000000007, 1000000009};
const int mul[2] = {10009, 10007};

int main() {
  string s, t;
  cin >> s >> t;
  int n = (int)s.size(), m = (int)t.size();
  int r = min(n, m);
  vector<vector<int>> pm(26, vector<int>(2));
  pm[0][0] = pm[0][1] = 1;
  rep(i, 25) {
    rep(j, 2) { pm[i + 1][j] = (ll)pm[i][j] * mul[j] % mod[j]; }
  }
  int ans = 0;
  for (int i = 1; i <= r; i++) {
    set<P> st;
    int val[2] = {};
    for (int j = 0; j < i; j++) {
      rep(k, 2) { val[k] = (val[k] + pm[s[j] - 'a'][k]) % mod[k]; }
    }
    st.insert(P(val[0], val[1]));
    for (int j = 0; j < n - i; j++) {
      rep(k, 2) {
        val[k] = (val[k] + mod[k] - pm[s[j] - 'a'][k]) % mod[k];
        val[k] = (val[k] + pm[s[j + i] - 'a'][k]) % mod[k];
      }
      st.insert(P(val[0], val[1]));
    }
    val[0] = val[1] = 0;
    for (int j = 0; j < i; j++) {
      rep(k, 2) { val[k] = (val[k] + pm[t[j] - 'a'][k]) % mod[k]; }
    }
    if (st.find(P(val[0], val[1])) != st.end()) {
      ans = i;
      continue;
    }
    for (int j = 0; j < m - i; j++) {
      rep(k, 2) {
        val[k] = (val[k] + mod[k] - pm[t[j] - 'a'][k]) % mod[k];
        val[k] = (val[k] + pm[t[j + i] - 'a'][k]) % mod[k];
      }
      if (st.find(P(val[0], val[1])) != st.end()) {
        ans = i;
        break;
      }
    }
  }
  cout << ans << "\\n";
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

using namespace std;

typedef pair<int, int> P;

const int mod = 1000000007;
const int mul = 10009;

int main() {
  string s, t;
  cin >> s >> t;
  int n = (int)s.size(), m = (int)t.size();
  vector<int> pm(26);
  pm[0] = 1;
  rep(i, 24) { pm[i + 1] = (ll)pm[i] * mul % mod; }
  set<P> st;
  rep(i, n) {
    int val = 0;
    for (int j = i; j < n; j++) {
      val = (val + pm[s[j] - 'a']) % mod;
      st.insert(P(val, j - i + 1));
    }
  }
  int ans = 0;
  rep(i, m) {
    int val = 0;
    for (int j = i; j < m; j++) {
      val = (val + pm[t[j] - 'a']) % mod;
      if (st.find(P(val, j - i + 1)) != st.end()) {
        ans = max(ans, j - i + 1);
      }
    }
  }
  cout << ans << "\\n";
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

typedef unsigned long long ull;
const ull p = 1000000007;
string S, T;

signed main() {
  ull power[26];
  power[0] = 1;
  for (int i = 1; i < 26; i++)
    power[i] = power[i - 1] * p;

  cin >> S >> T;
  vector<ull> hs;
  for (int i = min(S.size(), T.size()); i > 0; i--) {
    ull h = 0;
    hs.clear();
    for (int j = 0; j + 1 < i; j++) {
      h += power[T[j] - 'a'];
    }
    for (int j = i - 1; j < T.size(); j++) {
      h += power[T[j] - 'a'];
      hs.pb(h);
      h -= power[T[j - i + 1] - 'a'];
    }

    sort(all(hs));

    h = 0;
    for (int j = 0; j + 1 < i; j++) {
      h += power[S[j] - 'a'];
    }
    for (int j = i - 1; j < S.size(); j++) {
      h += power[S[j] - 'a'];
      if (binary_search(all(hs), h)) {
        cout << i << endl;
        return 0;
      }
      h -= power[S[j - i + 1] - 'a'];
    }
  }
  cout << 0 << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

typedef unsigned long long ull;
const ull p = 1000000007;
string S, T;

signed main() {
  ull power[26];
  power[0] = 1;
  for (int i = 1; i < 26; i++)
    power[i] = power[i - 1] * p;

  cin >> S >> T;

  set<ull> s;
  rep(i, T.size()) {
    ull h = 0;
    for (int j = i; j < T.size(); j++) {
      h += power[T[j] - 'a'];
      s.insert(h);
    }
  }

  int ma = 0;
  for (int i = 0; i < S.size(); i++) {
    ull h = 0;
    for (int j = i; j < S.size(); j++) {
      h += power[S[j] - 'a'];
      if (s.find(h) != s.end())
        chmax(ma, j - i + 1);
    }
  }
  cout << ma << endl;
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using vlai = array<int, 26>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, a, n) for (int i = a; i < n; i++)
int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    if (s1.size() > s2.size())
      swap(s1, s2);
    int n1 = s1.size(), n2 = s2.size();
    vector<vlai> h1(n1 + 1), h2(n2 + 1);

    rep(i, n1) {
      h1[i + 1] = h1[i];
      h1[i + 1][s1[i] - 'a']++;
    }
    rep(i, n2) {
      h2[i + 1] = h2[i];
      h2[i + 1][s2[i] - 'a']++;
    }

    set<vlai> list1;
    for (int l = n1; l >= 1; l--) {
      list1.clear();
      rep(i, n1 - l + 1) {
        auto his1 = h1[i + l];
        rep(j, 26) his1[j] -= h1[i][j];
        list1.insert(his1);
      }
      rep(i, n2 - l + 1) {
        auto his2 = h2[i + l];
        rep(j, 26) his2[j] -= h2[i][j];
        if (list1.find(his2) != list1.end()) {
          cout << l << endl;
          goto end;
        }
      }
    }
    cout << 0 << endl;
  end:;
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using vlai = array<int, 26>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, a, n) for (int i = a; i < n; i++)
int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    if (s1.size() > s2.size())
      swap(s1, s2);
    int n1 = s1.size(), n2 = s2.size();
    vector<vlai> h1(n1 + 1), h2(n2 + 1);

    rep(i, n1) {
      h1[i + 1] = h1[i];
      h1[i + 1][s1[i] - 'a']++;
    }
    rep(i, n2) {
      h2[i + 1] = h2[i];
      h2[i + 1][s2[i] - 'a']++;
    }
    vector<set<vlai>> list1(n1 + 1);
    for (int l = n1; l >= 1; l--)
      rep(i, n1 - l + 1) {
        auto his1 = h1[i + l];
        rep(j, 26) his1[j] -= h1[i][j];
        list1[l].insert(his1);
      }

    for (int l = n1; l >= 1; l--)
      rep(i, n2 - l + 1) {
        auto his2 = h2[i + l];
        rep(j, 26) his2[j] -= h2[i][j];
        if (list1[l].find(his2) != list1[l].end()) {
          cout << l << endl;
          goto end;
        }
      }
    cout << 0 << endl;
  end:;
  }
  return 0;
}