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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {

  int n, m;
  bool open = true;

  cin >> n;
  string tou[500];
  REP(i, n) { cin >> tou[i]; }
  cin >> m;
  string kita;
  REP(i, m) {
    cin >> kita;
    REP(j, n) {
      if (kita == tou[j]) {
        if (open) {
          cout << "Opened by " << kita << endl;
          open = (not open);
          break;
        } else {
          cout << "Closed by " << kita << endl;
          open = (not open);
          break;
        }
      }
      if (j == n - 1)
        cout << "Unknown " << kita << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {

  int n, m;
  bool open = true;

  cin >> n;
  string tou[200];
  REP(i, n) { cin >> tou[i]; }
  cin >> m;
  string kita;
  REP(i, m) {
    cin >> kita;
    REP(j, n) {
      if (kita == tou[j]) {
        if (open) {
          cout << "Opened by " << kita << endl;
          open = (not open);
          break;
        } else {
          cout << "Closed by " << kita << endl;
          open = (not open);
          break;
        }
      }
      if (j == n - 1)
        cout << "Unknown " << kita << endl;
    }
  }
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> ch(n);
  for (int i = 0; i < n; i++)
    cin >> ch[i];
  bool flag = false;
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string str;
    cin >> str;
    int j;
    for (j = 0; j < n; j++) {
      if (ch[j] == str) {
        if (flag) {
          cout << "Closed by"
               << " " << str << endl;
          flag = false;
          break;
        } else {
          cout << "Opened by"
               << " " << str << endl;
          flag = true;
          break;
        }
      }
    }
    if (j == n)
      cout << "Unknown"
           << " " << str << endl;
  }
  return 0;
}


Error: 0

Fixed submission:


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> ch(n);
  for (int i = 0; i < n; i++)
    cin >> ch[i];
  bool flag = false;
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string str;
    cin >> str;
    int j;
    for (j = 0; j < m; j++) {
      if (ch[j] == str) {
        if (flag) {
          cout << "Closed by " << str << endl;
          flag = false;
          break;
        } else {
          cout << "Opened by " << str << endl;
          flag = true;
          break;
        }
      }
    }
    if (j == m)
      cout << "Unknown " << str << endl;
  }
  return 0;
}
Problem p01554 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int N, M;
string U[257];

int main() {
  char s[11];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", s);
    U[i] = s;
  }
  scanf("%d", &M);
  bool opened = false;
  for (int i = 0; i < M; i++) {
    scanf("%s", s);
    const string *p = find(U, U + N, (string)s);
    if (!p->empty()) {
      opened = !opened;
      printf("%s by %s\\n", (opened ? "Opened" : "Closed"), s);
    } else {
      printf("Unknown %s\\n", s);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int N, M;
string U[256];

int main() {
  char s[14];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", s);
    U[i] = s;
  }
  scanf("%d", &M);
  bool opened = false;
  for (int i = 0; i < M; i++) {
    scanf("%s", s);
    const string *p = find(U, U + N, (string)s);
    if (!p->empty()) {
      opened = !opened;
      printf("%s by %s\\n", (opened ? "Opened" : "Closed"), s);
    } else {
      printf("Unknown %s\\n", s);
    }
  }
  return 0;
}
Problem p01555 (C++) — buggy submission, verdict: Runtime Error

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

ll calc(ll l, ll r, ll n) {
  l = ((l - 1) / n + 1) * n;
  if (l > r)
    return 0;
  return (r - l) / n + 1;
}

ll calc(ll x) {
  ll len = 0, num = 1, cnt = 1;
  while (num <= x) {
    ll nx = min(x + 1, num * 10);
    ll d3 = calc(num, nx - 1, 3);
    ll d5 = calc(num, nx - 1, 5);
    ll d15 = calc(num, nx - 1, 15);
    ll d = d3 + d5 - d15;
    len += ((nx - num) - d) * cnt;
    len += (d3 + d5) * 4;
    num = nx;
    cnt++;
    if (len > n)
      return len;
  }
  return len;
}

ll search() {
  ll L = 0, M, R = 1LL << 60;
  while (L < R) {
    M = (L + R) / 2;
    if (calc(M) >= n)
      R = M;
    else
      L = M + 1;
  }
  return L - 1;
}

string ItoS(ll a) {
  if (a == 0)
    return "0";
  string res;
  while (a)
    res = (char)(a % 10 + '0') + res, a /= 10;
  return res;
}

int main() {
  cin >> n;
  ll num = search() + 1;
  ll len = calc(num - 1);
  string ans;
  while (ans.size() < 100) {
    if (num % 3 == 0)
      ans += "Fizz";
    if (num % 5 == 0)
      ans += "Buzz";
    if (num % 3 && num % 5)
      ans += ItoS(num);
    num++;
  }
  for (int i = 0; i < 20; i++)
    cout << ans[n - len - 1 + i];
  cout << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll calc(ll l, ll r, ll n) {
  l = ((l - 1) / n + 1) * n;
  if (l > r)
    return 0;
  return (r - l) / n + 1;
}

ll calc(ll x) {
  ll len = 0, num = 1, cnt = 1;
  while (num <= x) {
    ll nx = min(x + 1, num * 10);
    ll d3 = calc(num, nx - 1, 3);
    ll d5 = calc(num, nx - 1, 5);
    ll d15 = calc(num, nx - 1, 15);
    ll d = d3 + d5 - d15;
    len += ((nx - num) - d) * cnt;
    len += (d3 + d5) * 4;
    num = nx;
    cnt++;
  }
  return len;
}

int search() {
  ll L = 0, M, R = 1LL << 55;
  while (L < R) {
    M = (L + R) / 2;
    if (calc(M) >= n)
      R = M;
    else
      L = M + 1;
  }
  return L - 1;
}

string ItoS(ll a) {
  if (a == 0)
    return "0";
  string res;
  while (a)
    res = (char)(a % 10 + '0') + res, a /= 10;
  return res;
}

int main() {
  cin >> n;
  ll num = search() + 1;
  ll len = calc(num - 1);
  string ans;
  while (ans.size() < 100) {
    if (num % 3 == 0)
      ans += "Fizz";
    if (num % 5 == 0)
      ans += "Buzz";
    if (num % 3 && num % 5)
      ans += ItoS(num);
    num++;
  }
  for (int i = 0; i < 20; i++)
    cout << ans[n - len - 1 + i];
  cout << endl;

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

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

ll calc(ll x, ll y, ll z) {
  ll xfb = x / 15, xf = x / 3 - xfb, xb = x / 5 - xfb;
  ll yfb = y / 15, yf = y / 3 - yfb, yb = y / 5 - yfb;
  ll X = (x - xfb - xf - xb) * z + xfb * 8 + xf * 4 + xb * 4;
  ll Y = (y - yfb - yf - yb) * z + yfb * 8 + yf * 4 + yb * 4;
  return Y - X;
}

ll po(ll a, ll b) {
  ll res = 1;
  for (ll i = 0; i < b; i++)
    res *= a;
  return res;
}

string fizzbuzz(ll i) {
  if (i % 15 == 0)
    return "FizzBuzz";
  else if (i % 5 == 0)
    return "Buzz";
  else if (i % 3 == 0)
    return "Fizz";
  else {
    stringstream ss;
    string res;
    ss << i;
    ss >> res;
    return res;
  }
}

ll func(ll x) {
  if (x == 0)
    return 0;
  ll i;
  for (i = 0; i < 18; i++)
    if (po(10, i) <= x && x < po(10, i + 1))
      break;
  ll res = t[po(10, i)];
  return res + calc(po(10, i), x, i + 1);
}

int main() {
  t[1] = 1;
  for (int i = 1; i < 18; i++) {
    t[po(10, i)] = t[po(10, i - 1)] + calc(po(10, i - 1), po(10, i) - 1, i) + 4;
  }

  ll n, L = 1, R = po(10, 17), M;
  cin >> n;
  while (L + 1 < R) {
    M = (L + R) / 2;
    ll res = func(M);
    if (res < n) {
      L = M + 1;
    } else {
      R = M;
    }
  }

  string ans = "";
  for (ll i = L; i <= L + 20; i++)
    ans = ans + fizzbuzz(i);
  for (ll i = 0; i < 20; i++) {
    cout << ans[n - func(L - 1) - 1 + i];
  }
  cout << endl;

  return 0;
}

Error: -11

Fixed submission:

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

ll calc(ll x, ll y, ll z) {
  ll xfb = x / 15, xf = x / 3 - xfb, xb = x / 5 - xfb;
  ll yfb = y / 15, yf = y / 3 - yfb, yb = y / 5 - yfb;
  ll X = (x - xfb - xf - xb) * z + xfb * 8 + xf * 4 + xb * 4;
  ll Y = (y - yfb - yf - yb) * z + yfb * 8 + yf * 4 + yb * 4;
  return Y - X;
}

ll po(ll a, ll b) {
  ll res = 1;
  for (ll i = 0; i < b; i++)
    res *= a;
  return res;
}

string fizzbuzz(ll i) {
  if (i % 15 == 0)
    return "FizzBuzz";
  else if (i % 5 == 0)
    return "Buzz";
  else if (i % 3 == 0)
    return "Fizz";
  else {
    stringstream ss;
    string res;
    ss << i;
    ss >> res;
    return res;
  }
}

ll func(ll x) {
  ll i;
  for (i = 0; i < 18; i++)
    if (po(10, i) <= x && x < po(10, i + 1))
      break;
  ll res = t[po(10, i)];
  return res + calc(po(10, i), x, i + 1);
}

int main() {
  t[1] = 1;
  for (int i = 1; i < 18; i++) {
    t[po(10, i)] = t[po(10, i - 1)] + calc(po(10, i - 1), po(10, i) - 1, i) + 4;
  }

  ll n, L = 1, R = po(10, 17), M;
  cin >> n;
  while (L + 1 < R) {
    M = (L + R) / 2;
    ll res = func(M);
    if (res < n) {
      L = M + 1;
    } else {
      R = M;
    }
  }
  string ans = "";
  for (ll i = L; i <= L + 20; i++)
    ans = ans + fizzbuzz(i);
  for (ll i = 0; i < 20; i++) {
    cout << ans[n - func(L - 1) - 1 + i];
  }
  cout << endl;

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

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

LL fz_add(LL x) { return (x / 3LL) + (x / 5LL); }

LL fz_cnt(LL x) { return (x / 3LL) + (x / 5LL) - (x / 15LL); }

LL count_char(LL x) {
  LL count = 0;

  for (LL z = 1, inc = 1; z <= x; ++inc) {
    z *= 10;
    if (z <= x) {
      count += inc * (z - (z / 10)) + 4 * (fz_add(z - 1) - fz_add(z / 10 - 1)) -
               inc * (fz_cnt(z - 1) - fz_cnt(z / 10 - 1));
    } else {
      count += inc * (x - (z / 10 - 1)) + 4 * (fz_add(x) - fz_add(z / 10 - 1)) -
               inc * (fz_cnt(x) - fz_cnt(z / 10 - 1));
    }
  }

  return count;
}

int main() {
  LL N;
  cin >> N;

  LL l, r, count;
  l = 0LL;
  r = 1000000000000000001LL;
  while (l + 1 < r) {
    LL m = (l + r) / 2;

    LL count = count_char(m);

    if (count < N) {
      l = m;
    } else {
      r = m;
    }
  }

  count = count_char(l);

  stringstream ss;
  for (LL x = l + 1; x <= l + 20; ++x) {
    if (x % 15 == 0) {
      ss << "FizzBuzz";
    } else if (x % 3 == 0) {
      ss << "Fizz";
    } else if (x % 5 == 0) {
      ss << "Buzz";
    } else {
      ss << x;
    }
  }

  string ret;
  ss >> ret;
  cout << ret.substr(N - count - 1, 20) << endl;

  return 0;
}

Error: MLE

Fixed submission:

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

LL fz_add(LL x) { return (x / 3LL) + (x / 5LL); }

LL fz_cnt(LL x) { return (x / 3LL) + (x / 5LL) - (x / 15LL); }

LL count_char(LL x) {
  LL count = 0;

  for (LL z = 1, inc = 1; z <= x; ++inc) {
    z *= 10;
    if (z <= x) {
      count += inc * (z - (z / 10)) + 4 * (fz_add(z - 1) - fz_add(z / 10 - 1)) -
               inc * (fz_cnt(z - 1) - fz_cnt(z / 10 - 1));
    } else {
      count += inc * (x - (z / 10 - 1)) + 4 * (fz_add(x) - fz_add(z / 10 - 1)) -
               inc * (fz_cnt(x) - fz_cnt(z / 10 - 1));
    }
  }

  return count;
}

int main() {
  LL N;
  cin >> N;

  LL l, r, count;
  l = 0LL;
  r = 1000000000000000001LL;
  while (l + 1 < r) {
    LL m = (l + r) / 2;

    LL count = count_char(m);

    if (count < N) {
      l = m;
    } else {
      r = m;
    }
  }

  count = count_char(l);

  stringstream ss;
  for (int x = l + 1; x <= l + 20; ++x) {
    if (x % 15 == 0) {
      ss << "FizzBuzz";
    } else if (x % 3 == 0) {
      ss << "Fizz";
    } else if (x % 5 == 0) {
      ss << "Buzz";
    } else {
      ss << x;
    }
  }

  string ret;
  ss >> ret;
  cout << ret.substr(N - count - 1, 20) << endl;

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

#include <iostream>
#include <string>
using namespace std;
long long n, power[19];
long long check(long long x) {
  long long ret = 0, d = to_string(x).size();
  if (d != 1)
    ret += 5;
  for (int i = 2; i < d; i++)
    ret += power[i - 2] * i * 48;
  ret +=
      ((x - power[d - 1] + 1) - (x / 3 - (power[d - 1] - 1) / 3) -
       (x / 5 - (power[d - 1] - 1) / 5) + (x / 15 - (power[d - 1] - 1) / 15)) *
      d;
  return ret + (x / 3 + x / 5) * 4;
}
int main() {
  cin >> n;
  power[0] = 1;
  for (int i = 1; i < 19; i++)
    power[i] = power[i - 1] * 10;
  long long l = 1, r = power[17];
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if (check(m) <= n)
      l = m;
    else
      r = m;
  }
  long long d = n - check(l - 1);
  string ret;
  for (long long i = l; i < l + 20; i++) {
    if (i % 15 == 0)
      ret += "FizzBuzz";
    else if (i % 3 == 0)
      ret += "Fizz";
    else if (i % 5 == 0)
      ret += "Buzz";
    else
      ret += to_string(i);
  }
  cout << ret.substr(d - 1, 20) << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 60)


Fixed submission:

#include <iostream>
#include <string>
using namespace std;
long long n, power[19];
long long check(long long x) {
  long long ret = 0, d = to_string(x).size();
  if (d != 1)
    ret += 5;
  for (int i = 2; i < d; i++)
    ret += power[i - 2] * i * 48;
  ret +=
      ((x - power[d - 1] + 1) - (x / 3 - (power[d - 1] - 1) / 3) -
       (x / 5 - (power[d - 1] - 1) / 5) + (x / 15 - (power[d - 1] - 1) / 15)) *
      d;
  return ret + (x / 3 + x / 5) * 4;
}
int main() {
  cin >> n;
  power[0] = 1;
  for (int i = 1; i < 19; i++)
    power[i] = power[i - 1] * 10;
  long long l = 1, r = power[17];
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if (check(m) <= n)
      l = m;
    else
      r = m;
  }
  long long d = n - check(l);
  string ret;
  for (long long i = r; i < r + 20; i++) {
    if (i % 15 == 0)
      ret += "FizzBuzz";
    else if (i % 3 == 0)
      ret += "Fizz";
    else if (i % 5 == 0)
      ret += "Buzz";
    else
      ret += to_string(i);
  }
  cout << ret.substr(d - 1, 20) << endl;
  return 0;
}
Problem p01555 (C++) — buggy submission, verdict: Runtime Error

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

ll length(ll n) {
  if (n == 0) {
    return 0;
  }
  ll k = 1, d = 1;
  while (10 * k <= n) {
    k *= 10;
    d++;
  }
  k--;
  ll n3 = n / 3 - k / 3;
  ll n5 = n / 5 - k / 5;
  ll n15 = n / 15 - k / 15;
  return length(k) + 4 * (n3 + n5) + d * (n - k - n3 - n5 + n15);
}

int main() {
  ll s;
  cin >> s;

  ll ok = 1, ng = 1e17, m;
  while (ng - ok > 1) {
    m = (ok + ng) / 2;
    ll l = length(m - 1);
    if (l <= s - 1) {
      ok = m;
    } else {
      ng = m;
    }
  }

  string r;
  for (ll i = ok; r.size() < 100; i++) {
    if (i % 15 == 0) {
      r += "FizzBuzz";
    } else if (i % 3 == 0) {
      r += "Fizz";
    } else if (i % 5 == 0) {
      r += "Buzz";
    } else {
      r += to_string(i);
    }
  }
  cout << r.substr(s - 1 - length(ok - 1), 20) << endl;
}


Error: 0
12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz1617Fizz19BuzzFizz2223FizzBuzz26Fizz2829FizzBuzz3132Fizz34


Fixed submission:

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

ll length(ll n) {
  if (n == 0) {
    return 0;
  }
  ll k = 1, d = 1;
  while (10 * k <= n) {
    k *= 10;
    d++;
  }
  k--;
  ll n3 = n / 3 - k / 3;
  ll n5 = n / 5 - k / 5;
  ll n15 = n / 15 - k / 15;
  return length(k) + 4 * (n3 + n5) + d * (n - k - n3 - n5 + n15);
}

int main() {
  ll s;
  cin >> s;

  ll ok = 1, ng = 1e17, m;
  while (ng - ok > 1) {
    m = (ok + ng) / 2;
    ll l = length(m - 1);
    if (l <= s - 1) {
      ok = m;
    } else {
      ng = m;
    }
  }

  string r;
  for (ll i = ok; r.size() < 100; i++) {
    if (i % 15 == 0) {
      r += "FizzBuzz";
    } else if (i % 3 == 0) {
      r += "Fizz";
    } else if (i % 5 == 0) {
      r += "Buzz";
    } else {
      r += to_string(i);
    }
  }
  cerr << r << endl;
  cout << r.substr(s - 1 - length(ok - 1), 20) << endl;
}
Problem p01555 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

long long getLen(long long n) {
  long long ret = 0;

  long long a = 1;
  long long b = 9;
  long long len = 1;
  while (a <= n) {
    b = min(b, n);
    long long fizzbuzz = b / 15 - (a - 1) / 15;
    long long fizz = b / 3 - (a - 1) / 3 - fizzbuzz;
    long long buzz = b / 5 - (a - 1) / 5 - fizzbuzz;

    ret += fizzbuzz * 8 + fizz * 4 + buzz * 4;
    ret += (b - a + 1 - fizzbuzz - fizz - buzz) * len;

    a *= 10;
    b = (b * 10) + 9;
    ++len;
  }

  return ret;
}

int main() {
  long long n;
  cin >> n;

  long long a = 0;
  long long b = 100000000000000000LL;
  while (a < b) {
    long long c = (a + b + 1) / 2;
    if (getLen(c) < n)
      a = c;
    else
      b = c - 1;
  }

  ostringstream oss;
  while (oss.str().size() < 100) {
    ++a;
    if (a % 3 == 0 || a % 5 == 0) {
      if (a % 3 == 0)
        oss << "Fizz";
      if (a % 5 == 0)
        oss << "Buzz";
    } else {
      oss << a;
    }
  }

  string s = oss.str();
  cout << s.substr(n - getLen(b) - 1, 20) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

long long getLen(long long n) {
  long long ret = 0;

  long long a = 1;
  long long b = 9;
  long long len = 1;
  while (a <= n) {
    b = min(b, n);
    long long fizzbuzz = b / 15 - (a - 1) / 15;
    long long fizz = b / 3 - (a - 1) / 3 - fizzbuzz;
    long long buzz = b / 5 - (a - 1) / 5 - fizzbuzz;

    ret += fizzbuzz * 8 + fizz * 4 + buzz * 4;
    ret += (b - a + 1 - fizzbuzz - fizz - buzz) * len;

    a *= 10;
    b = (b * 10) + 9;
    ++len;
  }

  return ret;
}

int main() {
  long long n;
  cin >> n;

  long long a = 0;
  long long b = 10000000000000000LL;
  while (a < b) {
    long long c = (a + b + 1) / 2;
    if (getLen(c) < n)
      a = c;
    else
      b = c - 1;
  }

  ostringstream oss;
  while (oss.str().size() < 100) {
    ++a;
    if (a % 3 == 0 || a % 5 == 0) {
      if (a % 3 == 0)
        oss << "Fizz";
      if (a % 5 == 0)
        oss << "Buzz";
    } else {
      oss << a;
    }
  }

  string s = oss.str();
  cout << s.substr(n - getLen(b) - 1, 20) << endl;

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

struct S {
  char v[10];
  int size;
  int c, d, e;
  long long b;
  S(const vector<int> &pv, int pc) : c(pc) {
    size = pv.size();
    copy(begin(pv), end(pv), begin(v));
    eval();
  }
  void eval() {
    b = 0;
    for (int i = 0; i < size; i++) {
      b = (b << 4) + v[i];
    }
    d = (v[0] != 1) + (v[size - 1] != size);
    for (int i = 0; i + 1 < size; i++) {
      d += abs(v[i] - v[i + 1]) > 1;
    }
    e = c + (d + 1) / 2;
  }
  void reverse(int a, int b) {
    c++;
    std::reverse(begin(v) + a, begin(v) + b + 1);
    eval();
  }
  bool operator<(const S &s) const { return e > s.e; }
};

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (auto &e : v) {
    cin >> e;
  }
  S is(v, 0);
  priority_queue<S> que;
  que.push(is);
  unordered_map<long long, int> m;
  m[is.b] = 0;
  for (;;) {
    S c = que.top();
    if (c.d == 0)
      break;
    que.pop();
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        S n = c;
        n.reverse(i, j);
        if (m.count(n.b) && m[n.b] <= n.c)
          continue;
        m[n.b] = n.c;
        que.push(n);
      }
    }
  }
  cout << que.top().c << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

struct S {
  vector<int> v;
  int c, d, e;
  S(const vector<int> &pv, int pc) : v(pv), c(pc) { eval(); }
  void eval() {
    d = 0;
    for (int i = 0; i < v.size() - 1; i++) {
      d += abs(v[i] - v[i + 1]) > 1;
    }
    e = c + (d + 1) / 2;
  }
  void reverse(int a, int b) {
    c++;
    std::reverse(begin(v) + a, begin(v) + b + 1);
    eval();
  }
  bool operator<(const S &s) const { return e > s.e; }
};

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (auto &e : v) {
    cin >> e;
  }
  S is(v, 0);
  priority_queue<S> que;
  que.push(is);
  map<vector<int>, int> m;
  for (;;) {
    S c = que.top();
    if (is_sorted(begin(c.v), end(c.v)))
      break;
    que.pop();
    if (m.count(c.v) && m[c.v] <= c.c)
      continue;
    m[c.v] = c.c;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        S n = c;
        n.reverse(i, j);
        que.push(n);
      }
    }
  }
  cout << que.top().c << endl;
}