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

#include <iostream>
#include <queue>

using namespace std;

int dp[1 << 16][16];

int main() {
  for (int n, m, l, s, t; cin >> n >> m >> l >> s >> t, n | m | l | s | t;) {
    int d[323][323];
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        d[i][j] = (i == j) ? 0 : 1e9;
      }
    }
    for (int i = 0; i < m; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      d[a][b] = d[b][a] = c;
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        for (int k = 0; k <= n; k++) {
          d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
      }
    }
    int js[323], e[323];
    for (int i = 0; i < l; i++) {
      cin >> js[i] >> e[i];
    }
    fill(*begin(dp), *end(dp), 1e9);
    for (int i = 0; i < l; i++) {
      dp[1 << i][i] = d[s][js[i]] + e[i];
    }
    int ans = 0;
    for (int i = 0; i < 1 << l; i++) {
      for (int j = 0; j < l; j++) {
        if (i >> j & 1) {
          for (int k = 0; k < l; k++) {
            if (j != k && i >> k & 1) {
              dp[i][j] =
                  min(dp[i][j], dp[i ^ 1 << j][k] + d[js[k]][js[j]] + e[j]);
            }
          }
          if (dp[i][j] <= t - d[s][js[j]]) {
            ans = max(ans, __builtin_popcount(i));
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>

using namespace std;

struct edge {
  int v, c;
};

struct S {
  int v, t, b;
  bool operator<(S s) const { return t > s.t; }
};

int main() {
  for (int n, m, l, s, t; cin >> n >> m >> l >> s >> t, n | m | l | s | t;) {
    int d[323][323];
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        d[i][j] = (i == j) ? 0 : 1e9;
      }
    }
    for (int i = 0; i < m; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      d[a][b] = d[b][a] = c;
    }
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        for (int k = 0; k <= n; k++) {
          d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
      }
    }
    int js[323], e[323];
    for (int i = 0; i < l; i++) {
      cin >> js[i] >> e[i];
    }
    vector<edge> G[17];
    for (int i = 0; i < l; i++) {
      for (int j = 0; j < l; j++) {
        if (i != j && d[js[i]][js[j]] < 1e8) {
          G[i].push_back({j, d[js[i]][js[j]]});
        }
      }
      if (d[js[i]][s] < 1e8) {
        G[l].push_back({i, d[js[i]][s]});
        G[i].push_back({l, d[js[i]][s]});
      }
    }
    priority_queue<S> que;
    que.push({l, 0, 0});
    int ans = 0;
    bool u[17][1 << 16] = {};
    while (!que.empty()) {
      auto c = que.top();
      if (c.t > t)
        break;
      que.pop();
      if (u[c.v][c.b]++)
        continue;
      if (c.v == l) {
        ans = max(ans, __builtin_popcount(c.b));
      }
      for (auto elm : G[c.v]) {
        que.push({elm.v, c.t + elm.c, c.b});
      }
      if (c.v < l) {
        que.push({c.v, c.t + e[c.v], c.b | 1 << c.v});
      }
    }
    cout << ans << endl;
  }
}
Problem p01679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
const int INF = 1e+8;
int dist[300][300];

int main() {
  while (1) {
    int n, m, l, s, t;
    cin >> n >> m >> l >> s >> t;
    --s;
    if (!n)
      break;
    REP(i, 300) REP(j, 300) dist[i][j] = INF;
    REP(i, m) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      dist[a][b] = c;
      dist[b][a] = c;
    }
    REP(k, n)
    REP(i, n) REP(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    vector<tuple<int, int>> siro;
    siro.emplace_back(s, 0);
    REP(i, l) {
      int j, e;
      cin >> j >> e;
      --j;
      siro.emplace_back(j, e);
    }
    ++l;
    vector<vector<int>> dp(1 << l, vector<int>(l, INF));
    dp[1][0] = 0;
    int num = 0;
    REP(i, 1 << l) {
      REP(j, l) {
        if (dp[i][j] < INF && ((i >> j) & 1) == 1) {
          if (dp[i][j] + dist[get<0>(siro[j])][get<0>(siro[0])] <= t) {
            int cnt = 0;
            REP(k, l) if (((i >> k) & 1) == 1)++ cnt;
            num = max(num, cnt - 1);
          }
          REP(k, l) {
            if (((i >> k) & 1) == 0) {
              int sj, se, tj, te;
              tie(sj, se) = siro[j];
              tie(tj, te) = siro[k];
              dp[i | (1 << k)][k] =
                  min(dp[i | (1 << k)][k], dp[i][j] + dist[sj][tj] + te);
            }
          }
        }
      }
    }
    cout << num << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
const int INF = 1e+8;

int main() {
  while (1) {
    int n, m, l, s, t;
    cin >> n >> m >> l >> s >> t;
    --s;
    if (!n)
      break;
    int dist[300][300];
    REP(i, 300) REP(j, 300) dist[i][j] = INF;
    REP(i, m) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      dist[a][b] = c;
      dist[b][a] = c;
    }
    REP(k, n)
    REP(i, n) REP(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    vector<tuple<int, int>> siro;
    siro.emplace_back(s, 0);
    REP(i, l) {
      int j, e;
      cin >> j >> e;
      --j;
      siro.emplace_back(j, e);
    }
    ++l;
    int dp[1 << l][l];
    REP(i, 1 << l) REP(j, l) dp[i][j] = INF;
    dp[1][0] = 0;
    int num = 0;
    REP(i, 1 << l) {
      REP(j, l) {
        if (dp[i][j] < INF && ((i >> j) & 1) == 1) {
          if (dp[i][j] + dist[get<0>(siro[j])][get<0>(siro[0])] <= t) {
            int cnt = 0;
            REP(k, l) if (((i >> k) & 1) == 1)++ cnt;
            num = max(num, cnt - 1);
          }
          REP(k, l) {
            if (((i >> k) & 1) == 0) {
              int sj, se, tj, te;
              tie(sj, se) = siro[j];
              tie(tj, te) = siro[k];
              dp[i | (1 << k)][k] =
                  min(dp[i | (1 << k)][k], dp[i][j] + dist[sj][tj] + te);
            }
          }
        }
      }
    }
    cout << num << endl;
  }
  return 0;
}
Problem p01680 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 + 7;

struct UnionFindTree {
  vector<int> v;
  vector<int> rank;
  int numgroup;

  UnionFindTree(int n) : v(n, -1), rank(n, 0), numgroup(n) {}
  int Find(int x) {
    if (v[x] < 0)
      return x;
    return v[x] = Find(v[x]);
  }
  void Union(int a, int b) {
    a = Find(a);
    b = Find(b);
    if (a == b)
      return;
    if (rank[a] < rank[b])
      swap(a, b);
    if (rank[a] == rank[b])
      rank[a]++;
    v[b] = a;
    numgroup--;
  }
};

lli modpow(lli n, lli p, lli mod) {
  lli res = 1;
  for (int i = 63; i >= 0; i--) {
    res = res * res % mod;
    if ((p & 1LL << i) != 0)
      res = res * n % mod;
  }
  return res;
}

int main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;

    UnionFindTree uft(n);
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      uft.Union(a, b);
    }
    if (m == 0) {
      cout << modpow(2, n, mod) << endl;
    } else {
      cout << (modpow(2, uft.numgroup, mod) + 1) % mod << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 + 7;

struct UnionFindTree {
  vector<int> v;
  vector<int> rank;
  int numgroup;

  UnionFindTree(int n) : v(n, -1), rank(n, 0), numgroup(n) {}
  int Find(int x) {
    if (v[x] < 0)
      return x;
    return v[x] = Find(v[x]);
  }
  void Union(int a, int b) {
    a = Find(a);
    b = Find(b);
    if (a == b)
      return;
    if (rank[a] < rank[b])
      swap(a, b);
    if (rank[a] == rank[b])
      rank[a]++;
    v[b] = a;
    numgroup--;
  }
};

lli modpow(lli n, lli p, lli mod) {
  lli res = 1;
  for (int i = 63; i >= 0; i--) {
    res = res * res % mod;
    if ((p & 1LL << i) != 0)
      res = res * n % mod;
  }
  return res;
}

int main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0)
      break;

    UnionFindTree uft(n);
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      uft.Union(a, b);
    }
    if (m == 0) {
      cout << modpow(2, n, mod) << endl;
    } else {
      cout << (modpow(2, uft.numgroup, mod) + 1) % mod << endl;
    }
  }
  return 0;
}
Problem p01682 (C++) — buggy submission, verdict: Time Limit Exceeded

// test copy file

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

int number(string &S, int &i);
int term(string &S, int &i);
int expr(string &S, int &i);

int number(string &S, int &i) {
  int ret = 0;
  while (isdigit(S[i])) {
    ret *= 10;
    ret += S[i] - '0';
    i++;
  }
  return ret;
}

int term(string &S, int &i) {
  const int64_t mod = 1000000007;
  if (S[i] == 'S') {
    i += 2; //"S<"
    int64_t x = expr(S, i);
    i++; //'>'
    x = x * x % mod;
    return x;
  } else {
    return number(S, i);
  }
}

int expr(string &S, int &i) {
  int ret = term(S, i);
  while (i < S.size()) {
    int cnt = 0;
    for (int j = i; j < S.size(); j++) {
      if (S[j] == '>')
        cnt++;
      else
        break;
    }
    if (cnt == 2 && i + 2 < S.size()) {
      i += 2; //">>"
      int y = term(S, i);
      if (y >= 31) {
        ret = 0;
      } else {
        ret >>= y;
      }
      continue;
    } else {
      return ret;
    }
  }
  return ret;
}

int main() {
  string S;
  while (getline(cin, S)) {
    if (S[0] == '#')
      break;
    int i = 0;
    string ss;
    for (auto c : S) {
      if (c != ' ')
        ss.push_back(c);
    }
    // cout<<ss<<endl;
    cout << expr(ss, i) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).*begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

const int INF = 150000000;
const long long M = 1000000007;

typedef string::const_iterator State;
int number(State &);
int term(State &);
int expression(State &);

// ??°??????????????????????????????????????°????????????
int number(State &begin) {
  int ret = 0;

  while (isdigit(*begin)) {
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }

  return ret;
}

// ?????????????????????????????????????????????????????????????????????
int term(State &begin) {
  if (*begin == 'S') {
    begin++; // '('????£???°??????
    begin++;
    long long ret = expression(begin);
    begin++; // ')'????£???°??????
    return ret * ret % M;
  } else {
    return number(begin);
  }
  return INF;
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
  int ret = term(begin);

  for (;;) {
    if (*begin == 'E')
      return ret;
    if (*begin == '>' && *(begin + 1) == '>' && *(begin + 2) != '>') {
      begin++;
      begin++;
      ret = ret >> min(term(begin), 31);
    } else {
      return ret;
    }
  }

  return ret;
}

inline void deleteSpace(string &a) {
  size_t pos;
  while ((pos = a.find_first_of(" ")) != string::npos) {
    a.erase(pos, 1);
  }
}

int main() {
  std::ifstream ifs("/Users/noy/Downloads/2570_in1.txt.html");
  string s;
  while (getline(cin, s), s != "#") {
    deleteSpace(s);
    s += "E";
    State tmp = s.begin();
    cout << expression(tmp) << endl;
  }
}
Problem p01682 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define _A_ 1

using namespace std;

typedef long long ll;
const ll MOD = 1000000007LL;

int len;
// string parse;
const int MAX = 2000010;
char parse[MAX];
int pos;

ll expression();

ll fact() {
  if (parse[pos] == 'S') {
    pos += 2; // S<xx>
    ll p = expression();
    if (pos >= len)
      return -1LL;
    pos++;
    return ((p % MOD) * (p % MOD)) % MOD;
  } else {
    if (pos >= len || !isdigit(parse[pos]))
      return -1LL;
    ll p = 0;
    while ('0' <= parse[pos] && parse[pos] <= '9') {
      p *= 10LL;
      p += (ll)(parse[pos] - '0');
      pos++;
    }
    return p;
  }
}

ll expression() {

  ll p = fact();

  if (p == -1LL)
    return -1LL;

  //

  while (parse[pos] == '>' && (pos + 1 < len && parse[pos + 1] == '>')) {
    int temp = pos;
    ll temp_v = p;
    pos += 2;

    ll q = fact();
    if (q == -1LL) {
      pos = temp;
      return temp_v;
    }
    for (ll i = 0; i < q; i++) {
      p >>= 1LL;
      if (p == 0LL)
        break;
    }
  }
  return p;
}

int main() {
  string s;
  while (_A_) {
    getline(cin, s);
    if (s == "#")
      break;
    string temp = "";
    len = 0;
    rep(i, (int)s.size()) if (s[i] != ' ') {
      parse[len] = s[i];
      len++;
    }
    pos = 0;
    parse[len] = '\\0';
    assert(len < MAX);
    // cout << expression() << endl;
    printf("%lld\\n", expression());
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define _A_ 1

using namespace std;

typedef long long ll;
const ll MOD = 1000000007LL;

int len;
// string parse;
const int MAX = 2000010;
char parse[MAX];
int pos;

ll expression();

ll fact() {
  if (parse[pos] == 'S') {
    pos += 2; // S<xx>
    ll p = expression();
    if (pos >= len)
      return -1LL;
    pos++;
    return ((p % MOD) * (p % MOD)) % MOD;
  } else {
    if (pos >= len || !isdigit(parse[pos]))
      return -1LL;
    ll p = 0;
    while ('0' <= parse[pos] && parse[pos] <= '9') {
      p *= 10LL;
      p += (ll)(parse[pos] - '0');
      pos++;
    }
    return p;
  }
}

ll expression() {

  ll p = fact();

  if (p == -1LL)
    return -1LL;

  //

  while (parse[pos] == '>' && (pos + 1 < len && parse[pos + 1] == '>')) {
    int temp = pos;
    ll temp_v = p;
    pos += 2;

    ll q = fact();
    if (q == -1LL) {

      pos = temp;
      return temp_v;
    }
    for (ll i = 0; i < q; i++)
      p >>= 1LL;
  }
  return p;
}

int main() {
  string s;
  while (_A_) {
    getline(cin, s);
    if (s == "#")
      break;
    string temp = "";
    len = 0;
    rep(i, (int)s.size()) if (s[i] != ' ') {
      parse[len] = s[i];
      len++;
    }
    pos = 0;
    parse[len] = '\\0';
    assert(len < MAX);
    // cout << expression() << endl;
    printf("%lld\\n", expression());
  }
  return 0;
}
Problem p01682 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).*begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

const int INF = 150000000;
const long long M = 1000000007;

typedef string::const_iterator State;
int number(int &);
int term(int &);
int expression(int &);

string s;

// ??°??????????????????????????????????????°????????????
int number(int &i) {
  int ret = 0;

  while (isdigit(s[i])) {
    ret *= 10;
    ret += s[i] - '0';
    i++;
  }

  return ret;
}

// ?????????????????????????????????????????????????????????????????????
int term(int &i) {
  if (s[i] == 'S') {
    i += 2;
    long long ret = expression(i);
    i++;
    return ret * ret % M;
  } else {
    return number(i);
  }
  return INF;
}

// ?????????????????????????????????????????????????????????????????????
int expression(int &i) {
  int ret = term(i);

  while (i < s.size() - 2) {
    if (s[i] == '>' && s[i + 1] == '>' && s[i + 2] != '>') {
      i += 2;
      ret = ret >> min(term(i), 31);
    } else {
      return ret;
    }
  }

  return ret;
}

inline void deleteSpace(string &a) {
  size_t pos;
  while ((pos = a.find_first_of(" ")) != string::npos) {
    a.erase(pos, 1);
  }
}

int main() {
  std::ifstream ifs("/Users/noy/Downloads/2570_in1.txt.html");
  while (getline(cin, s), s != "#") {
    // deleteSpace(s);
    string tmp;
    for (auto it : s) {
      if (it != ' ')
        tmp += it;
    }
    s = tmp;
    int i = 0;
    cout << expression(i) << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).*begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

const int INF = 150000000;
const long long M = 1000000007;

typedef string::const_iterator State;
int number(int &);
int term(int &);
int expression(int &);

string s;

// ??°??????????????????????????????????????°????????????
int number(int &i) {
  int ret = 0;

  while (isdigit(s[i])) {
    ret *= 10;
    ret += s[i] - '0';
    i++;
  }

  return ret;
}

// ?????????????????????????????????????????????????????????????????????
int term(int &i) {
  if (s[i] == 'S') {
    i += 2;
    long long ret = expression(i);
    i++;
    return ret * ret % M;
  } else {
    return number(i);
  }
  return INF;
}

// ?????????????????????????????????????????????????????????????????????
int expression(int &i) {
  int ret = term(i);

  while (i < s.size() - 2) {
    if (s[i] == '>' && s[i + 1] == '>' && s[i + 2] != '>') {
      i += 2;
      ret = ret >> min(term(i), 31);
    } else {
      return ret;
    }
  }

  return ret;
}

inline void deleteSpace(string &a) {
  size_t pos;
  while ((pos = a.find_first_of(" ")) != string::npos) {
    a.erase(pos, 1);
  }
}

int main() {
  std::ifstream ifs("/Users/noy/Downloads/2570_in1.txt.html");
  while (getline(cin, s), s != "#") {
    deleteSpace(s);
    int i = 0;
    cout << expression(i) << endl;
  }
}
Problem p01682 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = 1000000007LL;
string s;
int expr(int &p);
int term(int &p);
void sp(int &p);
int number(int &p);
int expr(int &p) {
  int res = term(p);
  sp(p);
  int q = p;
  while (q + 1 < (int)s.size() && s[q] == '>' && s[q + 1] == '>') {
    q += 2;
    sp(q);
    if (q >= (int)s.size() || s[q] == '>')
      break;
    p += 2;
    sp(p);
    int y = term(p);
    if (y > 31)
      res = 0;
    else
      res >>= y;
    sp(p);
    q = p;
  }
  return res;
}
int term(int &p) {
  int res;
  if (s[p] == 'S') {
    p++;
    sp(p);
    assert(s[p] == '<');
    p++;
    sp(p);
    int x = expr(p);
    sp(p);
    assert(s[p] == '>');
    p++;
    res = (x * x) % MOD;
  } else {
    res = number(p);
  }
  return res;
}
void sp(int &p) {
  while (p < (int)s.size() && s[p] == ' ')
    p++;
}
int number(int &p) {
  int res = 0;
  while (p < (int)s.size() && isdigit(s[p]))
    res = (res * 10 + s[p++] - '0') % MOD;
  return res;
}
signed main() {
  while (getline(cin, s), s != "#") {
    int p = 0;
    cout << expr(p) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = 1000000007LL;
string s;
int expr(int &p);
int term(int &p);
void sp(int &p);
int number(int &p);
int expr(int &p) {
  int res = term(p);
  sp(p);
  int q = p;
  while (q + 1 < (int)s.size() && s[q] == '>' && s[q + 1] == '>') {
    q += 2;
    sp(q);
    if (q >= (int)s.size() || !isdigit(s[q]))
      break;
    p += 2;
    sp(p);
    int y = term(p);
    if (y > 31)
      res = 0;
    else
      res >>= y;
    sp(p);
    q = p;
  }
  return res;
}
int term(int &p) {
  int res;
  if (s[p] == 'S') {
    p++;
    sp(p);
    assert(s[p] == '<');
    p++;
    sp(p);
    int x = expr(p);
    sp(p);
    assert(s[p] == '>');
    p++;
    res = (x * x) % MOD;
  } else {
    res = number(p);
  }
  return res;
}
void sp(int &p) {
  while (p < (int)s.size() && s[p] == ' ')
    p++;
}
int number(int &p) {
  int res = 0;
  while (p < (int)s.size() && isdigit(s[p]))
    res = (res * 10 + s[p++] - '0') % MOD;
  return res;
}
signed main() {
  while (getline(cin, s), s != "#") {
    int p = 0;
    cout << expr(p) << endl;
  }
  return 0;
}
Problem p01687 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int main(void) {
  string s1("AIDUNYAN"), s2("AIZUNYAN");
  string D;
  cin >> D;

  for (int i = 0; i < (int)(D.size() - s1.size() + 1); i++) {
    sort(s1.begin(), s1.end());
    do {
      if (equal(s1.begin(), s1.end(), D.substr(i, s1.size()).begin())) {
        D.replace(i, s2.size(), s2);
        i += s2.size() - 1;
        break;
      }
    } while (next_permutation(s1.begin(), s1.end()));
  }

  cout << D << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

int main(void) {
  string s1("AIDUNYAN"), s2("AIZUNYAN");
  string D;
  cin >> D;

  sort(s1.begin(), s1.end());

  for (int i = 0; i < (int)(D.size() - s1.size() + 1); i++) {
    sort(s1.begin(), s1.end());
    do {
      if (D.find(s1) == i) {
        D.replace(i, s2.size(), s2);
        i += s2.size();
        break;
      }
    } while (next_permutation(s1.begin(), s1.end()));
  }

  cout << D << endl;

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  string D;
  string S = "AIDUNYAN";
  string R = "AIZUNYAN";
  int len;
  cin >> D;
  len = D.size();
  D += "*****";
  sort(S.begin(), S.end());
  string ans = D;
  do {
    for (int i = 0; i <= D.size() - S.size(); i++) {
      if (D.substr(i, S.size()) == S) {
        for (int j = 0; j < S.size(); j++) {
          ans[i + j] = R[j];
        }
      }
    }
  } while (next_permutation(S.begin(), S.end()));
  cout << ans.substr(0, len) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  string D;
  string S = "AIDUNYAN";
  string R = "AIZUNYAN";
  cin >> D;
  sort(S.begin(), S.end());
  string ans = D;
  do {
    for (int i = 0; i <= D.size() - S.size(); i++) {
      if (D.substr(i, S.size()) == S) {
        for (int j = 0; j < S.size(); j++) {
          ans[i + j] = R[j];
        }
      }
    }
  } while (next_permutation(S.begin(), S.end()));
  cout << ans << endl;
  return 0;
}
Problem p01687 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
string S, T, V = "AIZUNYAN";
int main() {
  cin >> S;
  T = S;
  if (S.size() < 8) {
    cout << S << endl;
    return 0;
  }
  for (int i = 0; i < S.size() - 7; i++) {
    string U = S.substr(i, 8);
    char p[8];
    for (int j = 0; j < 8; j++) {
      p[j] = U[j];
    }
    sort(p, p + 8);
    U = "";
    for (int j = 0; j < 8; j++) {
      U += p[j];
    }
    if (U == "AADINNUY") {
      for (int j = 0; j < 8; j++) {
        T[i + j] = V[j];
      }
    }
  }
  cout << T << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
string S, T, V = "AIZUNYAN";
int main() {
  cin >> S;
  T = S;
  for (int i = 0; i < S.size() - 7; i++) {
    string U = S.substr(i, 8);
    char p[8];
    for (int j = 0; j < 8; j++) {
      p[j] = U[j];
    }
    U = "";
    for (int j = 0; j < 8; j++) {
      U += p[j];
    }
    if (U == "AIDUNYAN") {
      for (int j = 0; j < 8; j++) {
        T[i + j] = V[j];
      }
    }
  }
  cout << T << endl;
  return 0;
}