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

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using namespace std;

typedef pair<int, int> pii;

int main(void) {
  int n, m, a, b;
  int l[200000], r[200000];
  std::vector<pii> v;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    l[i] = r[i] = i;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b - 1));
  }
  std::sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    int lane = v[i].second;
    l[lane] = MIN(l[lane + 1], l[lane]);
    r[lane] = MAX(r[lane + 1], r[lane]);
    l[lane + 1] = MIN(l[lane], l[lane + 1]);
    r[lane + 1] = MAX(r[lane], r[lane + 1]);
    // cout<<"---"<<i<<"---"<<endl;
    // for(int j=0;j<n;j++){
    // cout<<l[j]<<" "<<r[j]<<endl;
    // }
  }

  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << r[i] - l[i] + 1 << " ";
    else
      cout << r[i] - l[i] + 1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> pii;

int main(void) {
  int n, m, a, b;
  std::vector<pii> v;
  cin >> n >> m;
  vector<std::list<int>> l(n + 1);
  for (int i = 1; i <= n; i++)
    l[i].push_back(i);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  std::sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    int lane = v[i].second;
    l[lane].merge(l[lane + 1]);
    l[lane].unique();
    l[lane + 1] = l[lane];
  }

  for (int i = 1; i <= n; i++) {
    if (i != n)
      cout << l[i].size() << " ";
    else
      cout << l[i].size() << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int n, m;
struct jxb {
  int x, y;
};
bool cmp(jxb b, jxb c) { return b.x < c.x; }
jxb a[100010];
int ans[200010];
map<int, int> mp;
map<int, int> f;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
  }
  sort(a + 1, a + m + 1, cmp);
  for (int i = 1; i <= n; i++)
    ans[i] = 1;
  for (int i = 1; i <= m; i++) {
    if (mp[a[i].y] == 1) {
      ans[a[i].y] = ans[a[i].y + 1] = ans[a[i].y] + ans[a[i].y + 1] - f[a[i].y];
      f[a[i].y] = ans[a[i].y];
    } else {
      mp[a[i].y] = 1;
      ans[a[i].y] += ans[a[i].y + 1];
      ans[a[i].y + 1] = ans[a[i].y];
      f[a[i].y] = ans[a[i].y];
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d", ans[i]);
    if (i != n)
      printf(" ");
  }
  printf("\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
struct node {
  int x, y;
};
bool cmp(node a, node b) { return a.x < a.y; }
node a[100005] = {0};
int n, m, ans[100005];
bool vis[100005];
int main() {
  cin >> n >> m;
  for (int q = 1; q <= n; q++) {
    vis[q] = true;
    ans[q] = 1;
  }
  for (int q = 0; q < m; q++)
    cin >> a[q].x >> a[q].y;
  sort(a, a + m, cmp);
  for (int q = 0; q < m; q++) {
    if (vis[a[q].y]) {
      vis[a[q].y] = false;
      int plus = ans[a[q].y + 1];
      ans[a[q].y + 1] += ans[a[q].y];
      ans[a[q].y] += plus;
    } else {
      ans[a[q].y] = max(ans[a[q].y + 1], ans[a[q].y]);
      ans[a[q].y + 1] = max(ans[a[q].y], ans[a[q].y + 1]);
    }
  }
  for (int q = 1; q < n; q++) {
    cout << ans[q] << " ";
  }
  cout << ans[n] << endl;
  return 0;
}
Problem p00948 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

#define pii pair<int, int>

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pii> v(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  sort(v.begin(), v.end());

  vector<pii> vp(n);
  for (int i = 0; i < n; i++)
    vp[i].first = i, vp[i].second = i;

  for (int i = 0; i < m; i++) {
    int x = v[i].second;
    vp[x].first = vp[x - 1].first;
    vp[x - 1].second = vp[x].second;
  }
  for (int i = 0; i < n; i++) {
    cout << vp[i].second - vp[i].first + 1;
    if (i < n - 1)
      cout << " ";
  }
  cout << endl;
}

Error: MLE

Fixed submission:

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

#define pii pair<int, int>

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pii> v(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  sort(v.begin(), v.end());

  vector<set<int>> vs(n);
  for (int i = 0; i < n; i++)
    vs[i].insert(i);

  for (int i = 0; i < m; i++) {
    int x = v[i].second;
    set<int> a = vs[x - 1], b = vs[x];
    if (a.size() < b.size())
      swap(a, b);
    a.insert(b.begin(), b.end());
    vs[x - 1] = a;
    vs[x] = a;
  }
  for (int i = 0; i < n; i++) {
    cout << vs[i].size();
    if (i < n - 1)
      cout << " ";
  }
  cout << endl;
}
Problem p00948 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct Pos {
  int y, x;
  Pos() {}
  Pos(int y, int x) {
    this->y = y;
    this->x = x;
  }
  bool operator<(const Pos &r) const { return (y != r.y) ? y < r.y : x < r.x; }
};

int n, m;
Pos arm[100000];
int dp[2][100000];

//?§??????????(dir=0:???, dir=1:???), (?????£????????£???)??¢???????????????id,
//??????????????????????????´???(0-indexed)?????????
int dfs(int dir, int id) {
  int nextId;

  if (dp[dir][id] != -1) {
    return dp[dir][id];
  }

  if (dir == 0) {
    nextId = upper_bound(arm, arm + m, Pos(arm[id].y - 1, arm[id].x)) - 1 - arm;
    if (nextId < 0 || arm[nextId].y != arm[id].y - 1)
      return arm[id].y;
    return dp[dir][id] = dfs(dir, nextId);
  }

  nextId = upper_bound(arm, arm + m, Pos(arm[id].y + 1, arm[id].x)) - 1 - arm;
  if (nextId < 0 || arm[nextId].y != arm[id].y + 1)
    return arm[id].y + 1;
  return dp[dir][id] = dfs(dir, nextId);
}

int main() {
  int i, j;

  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> arm[i].x >> arm[i].y;
    arm[i].y--;
  }
  sort(arm, arm + m);

  for (i = 0; i < 2; i++)
    for (j = 0; j < m; j++)
      dp[i][j] = -1;

  int id;
  for (i = 0; i < n; i++) {
    id = lower_bound(arm, arm + m, Pos(i, -1)) - 1 - arm;
    int low = ((id < 0 || arm[id].y != i - 1) ? i : dfs(0, id));
    id = lower_bound(arm, arm + m, Pos(i + 1, -1)) - 1 - arm;
    int high = ((id < 0 || arm[id].y != i) ? i : dfs(1, id));
    cout << high - low + 1;
    if (i + 1 < n)
      cout << " ";
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

struct Pos {
  int y, x;
  Pos() {}
  Pos(int y, int x) {
    this->y = y;
    this->x = x;
  }
  bool operator<(const Pos &r) const { return (y != r.y) ? y < r.y : x < r.x; }
};

int n, m;
Pos arm[100000];
int dp[2][100000];

//?§??????????(dir=0:???, dir=1:???), (?????£????????£???)??¢???????????????id,
//??????????????????????????´???(0-indexed)?????????
int dfs(int dir, int id) {
  int nextId;

  if (dir == 0) {
    nextId = upper_bound(arm, arm + m, Pos(arm[id].y - 1, arm[id].x)) - 1 - arm;
    if (nextId < 0 || arm[nextId].y != arm[id].y - 1)
      return arm[id].y;
    return dp[dir][id] = dfs(dir, nextId);
  }

  nextId = upper_bound(arm, arm + m, Pos(arm[id].y + 1, arm[id].x)) - 1 - arm;
  if (nextId < 0 || arm[nextId].y != arm[id].y + 1)
    return arm[id].y + 1;
  return dp[dir][id] = dfs(dir, nextId);
}

int main() {
  int i, j;

  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> arm[i].x >> arm[i].y;
    arm[i].y--;
  }
  sort(arm, arm + m);

  for (i = 0; i < 2; i++)
    for (j = 0; j < m; j++)
      dp[i][j] = -1;

  int id;
  for (i = 0; i < n; i++) {
    id = lower_bound(arm, arm + m, Pos(i, -1)) - 1 - arm;
    int low = ((id < 0 || arm[id].y != i - 1) ? i : dfs(0, id));
    id = lower_bound(arm, arm + m, Pos(i + 1, -1)) - 1 - arm;
    int high = ((id < 0 || arm[id].y != i) ? i : dfs(1, id));
    cout << high - low + 1;
    if (i + 1 < n)
      cout << " ";
  }
  cout << endl;
  return 0;
}
Problem p00948 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int>::iterator I;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v[n];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[y].push_back(-x);
  }
  for (int i = 0; i < n; i++)
    sort(v[i].begin(), v[i].end());
  map<I, int> m1, m2;
  vector<I> vi;
  for (int i = 0; i < n; i++) {
    int t = i, b = i + 1, p = -100000;
    vi.clear();
    while (1) {
      if (t == 0)
        break;
      I it = lower_bound(v[t].begin(), v[t].end(), p);
      if (it == v[t].end())
        break;
      if (m1.find(it) != m1.end()) {
        t = m1[it];
        break;
      }
      p = *it;
      t--;
      vi.push_back(it);
    }
    for (int j = 0; j < (int)vi.size(); j++)
      m1[vi[j]] = t;
    vi.clear();
    p = -100000;
    while (1) {
      if (b == n)
        break;
      I it = lower_bound(v[b].begin(), v[b].end(), p);
      if (it == v[b].end())
        break;
      if (m2.find(it) != m2.end()) {
        b = m2[it];
        break;
      }
      p = *it;
      b++;
      vi.push_back(it);
    }
    for (int j = 0; j < (int)vi.size(); j++)
      m2[vi[j]] = b;
    cout << b - t << " \\n"[i == n - 1];
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int>::iterator I;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v[n];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[y].push_back(-x);
  }
  for (int i = 0; i < n; i++)
    sort(v[i].begin(), v[i].end());
  map<I, int> m1, m2;
  vector<I> vi;
  for (int i = 0; i < n; i++) {
    int t = i, b = i + 1, p = -100000;
    vi.clear();
    while (1) {
      if (t == 0)
        break;
      I it = lower_bound(v[t].begin(), v[t].end(), p);
      if (it == v[t].end())
        break;
      if (m1.find(it) != m1.end()) {
        t = m1[it];
        break;
      }
      p = *it;
      t--;
      vi.push_back(it);
    }
    for (int j = 0; j < (int)vi.size(); j++)
      m1[vi[i]] = t;
    vi.clear();
    p = -100000;
    while (1) {
      if (b == n)
        break;
      I it = lower_bound(v[b].begin(), v[b].end(), p);
      if (it == v[b].end())
        break;
      if (m2.find(it) != m2.end()) {
        b = m2[it];
        break;
      }
      p = *it;
      b++;
      vi.push_back(it);
    }
    for (int j = 0; j < (int)vi.size(); j++)
      m2[vi[i]] = b;
    cout << b - t << " \\n"[i == n - 1];
  }
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {

  string s, t;
  cin >> s >> t;

  int ans = 0;

  for (int l = 1; l <= min(s.size(), t.size()); l++) {
    map<array<int, 26>, bool> mp;
    array<int, 26> a, b;
    rep(i, 26) a[i] = b[i] = 0;

    rep(i, l) a[s[i] - 'a']++;
    mp[a] = true;

    rep(i, s.size() - l) {
      a[s[i] - 'a']--;
      a[s[i + l] - 'a']++;
      mp[a] = true;
    }

    rep(i, l) b[t[i] - 'a']++;
    if (mp.count(b))
      ans = max(ans, l);

    rep(i, t.size() - l) {
      b[t[i] - 'a']--;
      b[t[i + l] - 'a']++;
      if (mp.count(b))
        ans = max(ans, l);
    }
  }
  cout << ans << endl;
}

Error: MLE

Fixed submission:

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

int main() {
  map<array<int, 26>, bool> mp[4001];

  string s, t;
  cin >> s >> t;

  int ans = 0;

  rep(i, s.size()) {
    array<int, 26> ar;
    rep(j, 26) ar[j] = 0;
    for (int j = i; j < s.size(); j++) {
      ar[s[j] - 'a']++;
      mp[j - i + 1][ar] = true;
    }
  }

  rep(i, t.size()) {
    array<int, 26> br;
    rep(j, 26) br[j] = 0;
    for (int j = i; j < t.size(); j++) {
      br[t[j] - 'a']++;
      if (mp[j - i + 1].count(br)) {
        ans = max(ans, j - i + 1);
      }
    }
  }
  cout << ans << endl;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3
#define B 1000000007

string s, t;
int n1, n2;
map<ull, bool> aru;
ull p[33];

int main() {
  cin >> s >> t;
  n1 = s.size();
  n2 = t.size();
  p[0] = 1;
  rep(i, 30) p[i + 1] = p[i] * B;
  int res = 0;
  repl(len, 1, min(n1, n2) + 1) {
    aru.clear();
    ull h = 0;
    for (int i = 0; i < n1; i++) {
      ull c = s[i] - 'a';
      if (i - len >= 0) {
        ull prec = s[i - len] - 'a';
        h -= p[prec];
      }
      h += p[c];
      if (i >= len - 1)
        aru[h] = true;
    }
    h = 0;
    for (int i = 0; i < n2; i++) {
      ull c = t[i] - 'a';
      if (i - len >= 0) {
        ull prec = t[i - len] - 'a';
        h -= p[prec];
      }
      h += p[c];
      if (i >= len - 1 && aru[h])
        maxch(res, len);
    }
  }
  cout << res << endl;
  return 0;
}


Error: MLE

Fixed submission:

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

typedef long long ll;
typedef unsigned int ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3
#define B 10007

string s, t;
int n1, n2;
unordered_map<ull, bool> aru;
ull p[33];

int main() {
  cin >> s >> t;
  n1 = s.size();
  n2 = t.size();
  p[0] = 1;
  rep(i, 30) p[i + 1] = p[i] * B;
  rep(i, n1) {
    ull h = 0;
    repl(j, i, n1) {
      ull c = s[j] - 'a';
      h += p[c];
      aru[h] = true;
    }
  }
  int res = 0;
  rep(i, n2) {
    ull h = 0;
    repl(j, i, n2) {
      ull c = t[j] - 'a';
      h += p[c];
      if (aru[h])
        maxch(res, j - i + 1);
    }
  }
  cout << res << endl;
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef pair<int, int> pii;

int main() {
  string a, b;
  cin >> a >> b;

  int l = min(a.size(), b.size());
  for (int len = l; len >= 1; len--) {
    set<vector<int>> ana;

    vector<int> cnt(26, 0);
    rep(i, len) cnt[a[i] - 'a']++;
    ana.insert(cnt);

    for (int i = len; i < (int)a.size(); i++) {
      cnt[a[i] - 'a']++;
      cnt[a[i - len] - 'a']--;
      ana.insert(cnt);
    }

    cnt = vector<int>(26, 0);
    rep(i, len) cnt[b[i] - 'a']++;
    if (ana.count(cnt)) {
      cout << len << endl;
      return 0;
    }

    for (int i = len; i < (int)b.size(); i++) {
      cnt[b[i] - 'a']++;
      cnt[b[i - len] - 'a']--;
      if (ana.count(cnt)) {
        cout << len << endl;
        return 0;
      }
    }
  }

  cout << 0 << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef pair<int, int> pii;

int main() {
  string a, b;
  cin >> a >> b;

  set<vector<int>> ana;
  rep(i, a.size()) {
    vector<int> cnt(26, 0);
    for (int j = i; j < (int)a.size(); j++) {
      cnt[a[j] - 'a']++;
      ana.insert(cnt);
    }
  }

  int ans = 0;
  rep(i, b.size()) {
    vector<int> cnt(26, 0);
    for (int j = i; j < (int)b.size(); j++) {
      cnt[b[j] - 'a']++;
      if (j - i + 1 <= ans)
        continue;
      if (ana.count(cnt))
        ans = max(ans, j - i + 1);
    }
  }

  cout << ans << endl;
}
Problem p00949 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \\
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << " : " << x << endl
#define ALL(v) (v).begin(), (v).end()

typedef vector<short> vi;

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  int ans = 0;
  FOR(l, 1, min(n, m) + 1) {
    set<vi> S;
    vi op(26, 0);
    REP(i, l - 1) op[s[i] - 'a']++;
    FOR(i, l - 1, n) {
      op[s[i] - 'a']++;
      S.insert(op);
      op[s[i + 1 - l] - 'a']--;
    }
    op = vi(26, 0);
    REP(i, l - 1) op[t[i] - 'a']++;
    FOR(i, l - 1, m) {
      op[t[i] - 'a']++;
      if (S.count(op)) {
        ans = l;
        break;
      }
      op[t[i + 1 - l] - 'a']--;
    }
  }
  printf("%d\\n", ans);
  return 0;
}

Error: MLE

Fixed submission:

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

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \\
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << " : " << x << endl
#define ALL(v) (v).begin(), (v).end()

typedef vector<short> vi;

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  set<vi> S;
  int ans = 0;
  REP(i, n) {
    vi op(26, 0);
    FOR(j, i, n) {
      op[s[j] - 'a']++;
      S.insert(op);
    }
  }
  REP(i, m) {
    vi op(26, 0);
    FOR(j, i, m) {
      op[t[j] - 'a']++;
      if (S.count(op)) {
        ans = max(ans, j - i + 1);
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00949 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define fi first
#define se second

#define INF 2147483600

char c1[4010], c2[4010];

int main() {
  scanf("%s %s", c1, c2);
  string s1(c1), s2(c2);
  if (s1.size() > s2.size())
    swap(s1, s2);

  for (int l = s1.size(); l > 0; l--) {
    set<vector<int>> st;
    vector<int> rui(26, 0);
    rep(i, l - 1) rui[s1[i] - 'a']++;
    rep(i, s1.size() - l + 1) {
      rui[s1[i + l - 1] - 'a']++;
      vector<int> vec(rui);
      st.insert(vec);
      rui[s1[i] - 'a']--;
    }
    rui = vector<int>(26, 0);
    rep(i, l - 1) rui[s2[i] - 'a']++;
    rep(i, s2.size() - l + 1) {
      rui[s2[i + l - 1] - 'a']++;
      if (st.find(rui) != st.end()) {
        cout << l << endl;
        return 0;
      }
      rui[s2[i] - 'a']--;
    }
  }
  cout << 0 << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define fi first
#define se second

#define INF 2147483600

char c1[4010], c2[4010];

int main() {
  scanf("%s %s", c1, c2);
  string s1(c1), s2(c2);
  if (s1.size() > s2.size())
    swap(s1, s2);

  // s1??????????????????

  for (int l = s1.size(); l > 0; l--) {
    unordered_set<string> st;
    rep(i, s1.size() - l + 1) {
      string str = s1.substr(i, l);
      sort(all(str));
      st.insert(str);
    }
    rep(i, s2.size() - l + 1) {
      string str = s2.substr(i, l);
      sort(all(str));
      if (st.find(str) != st.end()) {
        cout << l << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;

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

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

ll h[26][5010];
mt19937_64 mt;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef LOCAL
  std::ifstream in("in");
  std::cin.rdbuf(in.rdbuf());
#endif

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 5010; j++) {
      h[i][j] = mt();
    }
  }

  string s, t;
  cin >> s >> t;

  int n = s.size(), m = t.size();
  int ans = 0;
  for (int len = min(n, m); len >= 1; len--) {
    int cnt[26] = {0};
    for (int i = 0; i < len; i++) {
      cnt[s[i] - 'a']++;
    }
    ll hash = 0;
    for (int i = 0; i < 26; i++) {
      hash ^= h[i][cnt[i]];
    }
    set<ll> hs;
    hs.insert(hash);
    for (int i = len; i < n; i++) {
      int add = s[i] - 'a', sub = s[i - len] - 'a';
      hash ^= h[add][cnt[add]];
      hash ^= h[sub][cnt[sub]];
      cnt[add]++;
      cnt[sub]--;
      hash ^= h[add][cnt[add]];
      hash ^= h[sub][cnt[sub]];
      hs.insert(hash);
    }

    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < len; i++) {
      cnt[t[i] - 'a']++;
    }
    hash = 0;
    for (int i = 0; i < 26; i++) {
      hash ^= h[i][cnt[i]];
    }
    if (hs.count(hash)) {
      // cout << t.substr(0, len) << endl;
      ans = len;
      break;
    }
    for (int i = len; i < m; i++) {
      int add = t[i] - 'a', sub = t[i - len] - 'a';
      hash ^= h[add][cnt[add]];
      hash ^= h[sub][cnt[sub]];
      cnt[add]++;
      cnt[sub]--;
      hash ^= h[add][cnt[add]];
      hash ^= h[sub][cnt[sub]];
      if (hs.count(hash)) {
        // cout << t.substr(i - len + 1, len) << endl;
        ans = len;
        break;
      }
    }
    if (ans)
      break;
  }

  cout << ans << endl;
}

Error: MLE

Fixed submission:

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

ll h[26][5010];
mt19937_64 mt;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef LOCAL
  std::ifstream in("in");
  std::cin.rdbuf(in.rdbuf());
#endif

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 5010; j++) {
      h[i][j] = mt();
    }
  }

  string s, t;
  cin >> s >> t;

  int n = s.size(), m = t.size();
  set<ll> hs;
  for (int i = 0; i < n; i++) {
    ll hash = 0;
    for (int j = 0; j < 26; j++) {
      hash ^= h[j][0];
    }
    int cnt[26] = {0};
    for (int j = i; j < n; j++) {
      int id = s[j] - 'a';
      hash ^= h[id][cnt[id]];
      cnt[id]++;
      hash ^= h[id][cnt[id]];
      hs.insert(hash);
      int len = j - i + 1;
      // cout << s.substr(i, len) << endl;
    }
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    ll hash = 0;
    for (int j = 0; j < 26; j++) {
      hash ^= h[j][0];
    }
    int cnt[26] = {0};
    for (int j = i; j < m; j++) {
      int id = t[j] - 'a';
      hash ^= h[id][cnt[id]];
      cnt[id]++;
      hash ^= h[id][cnt[id]];
      int len = j - i + 1;
      if (hs.count(hash)) {
        // cout << t.substr(i, len) << endl;
        ans = max(ans, len);
      }
    }
  }
  cout << ans << endl;
}