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

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1 << 29;
const int N_MAX = 100000;
const double EPS = 1e-4;

template <class T> inline string itos(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
inline int stoi(string s) {
  int ret;
  stringstream ss(s);
  ss >> ret;
  return ret;
}

double dp[N_MAX + 2][31];
double ans[N_MAX + 1];

int main() {
  int n;

  dp[1][1] = 1.0;
  for (int i = 0; i <= N_MAX; i++) {
    double prob = 1.0;
    for (int j = 1; j < 30; j++) {
      prob /= 2.0;
      if (i + j + 1 > N_MAX) {
        break;
      }

      if (dp[i + j][j] == 0) {
        continue;
      }

      dp[i + j + 1][j + 1] += dp[i + j][j] * prob;
      dp[i + j + 2][1] += (1 - prob) * dp[i + j][j];
    }
  }
  /*
          for(int i = 1; i <= 10; i++)
          {
                  for(int j = 1; j < 10; j++)
                  {
                          printf("%.5lf ",dp[i][j]);
                  }
                  puts("");
          }
  */
  double sum = 0;

  for (int i = 0; i <= N_MAX; i++) {
    for (int j = 0; j < 30; j++) {
      sum += dp[i][j];
    }
    ans[i] = sum;
  }

  while (cin >> n, n) {
    printf("%f\\n", ans[n]);
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1 << 29;
const int N_MAX = 100000;
const double EPS = 1e-4;

template <class T> inline string itos(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
inline int stoi(string s) {
  int ret;
  stringstream ss(s);
  ss >> ret;
  return ret;
}

double dp[N_MAX + 2][31];
double ans[N_MAX + 1];

int main() {
  int n;

  dp[1][1] = 1.0;
  for (int i = 0; i <= N_MAX; i++) {
    double prob = 1.0;
    for (int j = 1; j < 30; j++) {
      if (dp[i + j][j] == 0) {
        continue;
      }
      if (i + j + 1 > N_MAX) {
        break;
      }
      dp[i + j + 1][j + 1] += dp[i + j][j] * dp[i + j][j] / 2;
      dp[i + j + 1][1] += (1 - dp[i + j][j]);

      if (dp[i + j + 1][j + 1] <= EPS) {
        break;
      }
    }
  }
  double sum = 0;
  for (int i = 0; i <= N_MAX; i++) {
    for (int j = 0; j < 30; j++) {
      sum += dp[i][j];
    }
    ans[i] = sum;
  }

  while (cin >> n, n) {
    printf("%f\\n", ans[n]);
  }
}
Problem p00642 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

double dp[100010][30];
double ans[100010];

int main() {
  memset(dp, 0, sizeof(dp));
  memset(ans, 0, sizeof(ans));
  dp[1][1] = 1;
  for (int i = 1; i < 100010; i++) {
    double p = 1, acc = 0;
    // double acc = 0;
    for (int j = 1; j < 30; j++) {
      dp[i + 1][j + 1] += dp[i][j] * p;
      dp[i + 1][1] += dp[i][j] * (1 - p);
      acc += dp[i][j] * p;
      p /= 2;
    }
    ans[i] = acc + ans[i - 1];
  }
  int n;
  while (scanf("%d", &n), n != 0) {
    printf("%.5f\\n", ans[n]);
  }
}

Error: MLE

Fixed submission:

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

double dp[100010][100];
double ans[100010];

int main() {
  memset(dp, 0, sizeof(dp));
  memset(ans, 0, sizeof(ans));
  dp[1][1] = 1;
  for (int i = 1; i < 100010; i++) {
    double p = 1, acc = 0;
    // double acc = 0;
    for (int j = 1; j < 100; j++) {
      dp[i + 1][j + 1] += dp[i][j] * p;
      dp[i + 1][1] += dp[i][j] * (1 - p);
      acc += dp[i][j] * p;
      p /= 2;
    }
    ans[i] = acc + ans[i - 1];
  }
  int n;
  while (scanf("%d", &n), n != 0) {
    printf("%.5f\\n", ans[n]);
  }
}
Problem p00644 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  for (int n, m, p; cin >> n >> m >> p, n;) {
    double nr[100][100] = {};
    int d[100][100];
    const int INF = 1 << 29;
    fill(d[0], d[100], INF);
    for (int i = 0; i < n; i++) {
      d[i][i] = 0;
    }
    while (m--) {
      int s, t, u;
      cin >> s >> t >> u;
      d[s][t] = d[t][s] = u;
      nr[s][t] = nr[t][s] = 1;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          int nd = d[j][i] + d[i][k];
          if (nd <= d[j][k]) {
            if (nd < d[j][k]) {
              nr[j][k] = 0;
            }
            d[j][k] = nd;
            nr[j][k] += nr[j][i] * nr[i][k];
          }
        }
      }
    }
    while (p--) {
      int c;
      cin >> c;
      cout.precision(9);
      cout << fixed
           << ((c == 0 || c == n - 1) ? 1
               : (d[0][c] + d[c][n - 1] != d[0][n - 1])
                   ? 0
                   : nr[0][c] * nr[c][n - 1] / nr[0][n - 1])
           << endl;
    }
    cout << endl;
  }
}

Error: MLE

Fixed submission:

// 29
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

struct S {
  int v, d;
  double p;
  bool operator<(S a) const { return d > a.d; }
};

int main() {
  for (int n, m, pp; cin >> n >> m >> pp, n | m | pp;) {
    int d[100][100];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = (i == j) ? 0 : 1 << 29;
      }
    }
    bool cn[100][100];
    while (m--) {
      int s, t, w;
      cin >> s >> t >> w;
      d[s][t] = d[t][s] = w;
      cn[s][t] = cn[t][s] = true;
    }
    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]);
        }
      }
    }
    priority_queue<S> que;
    S is = {0, 0, 1};
    que.push(is);
    double p[100] = {};
    while (!que.empty()) {
      S c = que.top();
      que.pop();
      p[c.v] += c.p;
      int nb = 0;
      for (int i = 0; i < n; i++) {
        nb += c.d + d[c.v][i] == d[0][i] && cn[c.v][i];
      }
      for (int i = 0; i < n; i++) {
        if (c.d + d[c.v][i] == d[0][i] && cn[c.v][i]) {
          S n = {i, d[0][i], c.p / nb};
          que.push(n);
        }
      }
    }
    while (pp--) {
      int c;
      cin >> c;
      cout << fixed << p[c] << endl;
    }
    cout << endl;
  }
  return 0;
}
Problem p00645 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int n, g, bit;
int dis[1 << 20];
vector<int> mask[5][5];

int rec(int g, int t) {
  if (t == 5) {
    if ((g & 31))
      return 1000000;
    return dis[g >> 5];
  }

  int res = rec(g, t + 1);
  for (int i = 0; i < mask[0][t].size(); i++) {
    res = min(res, rec(g ^ mask[0][t][i], t + 1) + 1);
  }
  return res;
}

int main() {
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = i; k < 5; k++) {
        for (int l = j; l < 5; l++) {
          int tmp = 0;
          for (int y = i; y <= k; y++) {
            for (int x = j; x <= l; x++) {
              tmp |= 1 << (y * 5 + x);
            }
          }
          mask[i][j].push_back(tmp);
        }
      }
    }
  }

  for (int i = 0; i < (1 << 20); i++)
    dis[i] = -1;
  dis[0] = 0;
  queue<int> q;
  q.push(0);
  while (q.size()) {
    int p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 5; j++) {
        for (int k = 0; k < mask[i][j].size(); k++) {
          if (mask[i][j][k] >= 1 << 20)
            continue;
          int nxt = p ^ mask[i][j][k];
          if (dis[nxt] < 0) {
            dis[nxt] = dis[p] + 1;
            q.push(nxt);
          }
        }
      }
  }

  while (cin >> n, n) {
    g = 0;
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        if (i < n && j < n) {
          cin >> bit;
          g |= bit << (i * 5 + j);
        }
      }
    }
    if (n < 5) {
      for (int i = 0; i < dis[g]; i++)
        cout << "myon";
      cout << endl;
    } else {
      int tmp = rec(g, 0);
      for (int i = 0; i < tmp; i++)
        cout << "myon";
      cout << endl;
    }
  }
}

Error: MLE

Fixed submission:

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

int n, m[5][5];
int dp[1 << (5 * 5)];
vector<int> mask[6];

int main() {
  for (n = 1; n <= 5; n++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int t1 = 0;
        for (int k = i; k < n; k++) {
          t1 += 1 << k;
          int t2 = 0;
          for (int l = j; l < n; l++) {
            t2 += (t1 << n * l);
            mask[n].push_back(t2);
          }
        }
      }
    }
  }

  while (1) {
    cin >> n;
    if (!n)
      break;
    int N = (1 << (n * n));

    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        cin >> m[i][j];

    int ans = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (m[i][j])
          ans += 1 << (i * n + j);

    for (int i = 0; i < N; i++)
      dp[i] = -1;
    dp[ans] = 0;
    queue<int> q;
    q.push(ans);

    while (q.size()) {
      int hoge = q.front();
      q.pop();
      if (!hoge)
        break;

      for (int i = 0; i < (int)mask[n].size(); i++) {
        int tmp = hoge ^ mask[n][i];
        if (dp[tmp] < 0) {
          dp[tmp] = dp[hoge] + 1;
          q.push(tmp);
        }
      }
    }

    for (int j = 0; j < dp[0]; j++)
      cout << "myon";
    cout << endl;
  }
}
Problem p00645 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>
using namespace std;
int b[6][6];
int rec[6][6][6][6];
int n;
int solve(int p, int q, int t, int c) {
  if (t == 0) {
    if (c)
      return 0;
    return 1;
  }
  if (p == n)
    return 0;
  if (q == n)
    return solve(p + 1, 0, t, c);
  if (!(c & (1 << (p * n + q))))
    return solve(p, q + 1, t, c);
  for (int h = q; h < n; h++) {
    for (int i = p; i < n; i++) {
      if (solve(p, q + 1, t - 1, c ^ rec[p][q][i][h]))
        return 1;
    }
  }
  return 0;
}
int main() {
  int a;
  while (scanf("%d", &a), a) {
    n = a;
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++)
        for (int k = 0; k < 6; k++)
          for (int l = 0; l < 6; l++)
            rec[i][j][k][l] = 0;
    for (int i = 0; i < a; i++)
      for (int j = 0; j < a; j++) {
        for (int k = i; k < a; k++)
          for (int l = j; l < a; l++) {
            for (int x = i; x <= k; x++)
              for (int y = j; y <= l; y++)
                rec[i][j][k][l] += (1 << (x * a + y));
          }
      }
    for (int i = 0; i < a; i++)
      for (int j = 0; j < a; j++)
        scanf("%d", &b[i][j]);
    int st = 0;
    for (int i = 0; i < a; i++)
      for (int j = 0; j < a; j++)
        if (b[i][j])
          st += (1 << (i * a + j));
    for (int i = 1;; i++) {
      if (solve(0, 0, i, st)) {
        for (int j = 0; j < i; j++)
          printf("myon");
        printf("\\n");
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int b[6][6];
int c[6][6];
int n;
int solve(int p, int q, int t) {
  if (t == 0) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (c[i][j])
          return 0;
    return 1;
  }
  if (p == n)
    return 0;
  if (q == n)
    return solve(p + 1, 0, t);
  if (!c[p][q])
    return solve(p, q + 1, t);
  for (int h = q; h < n; h++) {
    for (int i = p; i < n; i++) {
      for (int j = q; j <= h; j++)
        c[i][j] ^= 1;
      if (solve(p, q + 1, t - 1))
        return 1;
    }
    for (int i = p; i < n; i++)
      for (int j = q; j <= h; j++)
        c[i][j] ^= 1;
  }
  return 0;
}
int main() {
  int a;
  while (scanf("%d", &a), a) {
    n = a;
    for (int i = 0; i < a; i++)
      for (int j = 0; j < a; j++)
        scanf("%d", &b[i][j]);
    for (int i = 1;; i++) {
      for (int j = 0; j < a; j++)
        for (int k = 0; k < a; k++)
          c[j][k] = b[j][k];
      if (solve(0, 0, i)) {
        for (int j = 0; j < i; j++)
          printf("myon");
        printf("\\n");
        break;
      }
    }
  }
}
Problem p00645 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;

int N;

vector<int> mem;
vector<int> mas;

vector<int> item[25];

int w[16];
int h[16];
int a[4][4];
int memo[(1 << 25) / 6 + 10];

char dfs(int bit) {

  if (bit == 0)
    return 0;
  int idx = bit / 6;
  int pos = (bit % 6) * 5;
  // cout << pos << endl;
  char val = memo[idx] >> pos & ((1 << 5) - 1);
  // cout << (int)val << endl;
  if (val != ((1 << 5) - 1))
    return val;

  char ans = 30;
  for (int p = 0; p < 25; p++) {
    if (bit >> p & 1) {
      for (int i = 0; i < item[p].size(); i++)
        ans = min(ans, (char)(dfs(bit ^ item[p][i]) + 1));
      break;
    }
  }
  memo[idx] &= ~(((1 << 5) - 1) << pos);
  memo[idx] |= ((int)ans << pos);
  return ans;
}

int main() {
  memset(memo, -1, sizeof(memo));

  for (int w = 1; w <= 5; w++) {
    for (int h = 1; h <= 5; h++) {
      for (int i = 0; i <= 5 - h; i++) {
        for (int j = 0; j <= 5 - w; j++) {
          int mask = 0;
          for (int k = 0; k < h; k++)
            for (int l = 0; l < w; l++)
              mask |= (1 << ((i + k) * 5 + j + l));
          // cout << init << " " << mask << endl;
          item[i * 5 + j].push_back(mask);
        }
      }
    }
  }
  while (cin >> N && N) {
    int init = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        int c = 0;
        cin >> c;
        init |= (c << (i * 5 + j));
      }
    }
    // cout << init << endl;
    int x = (int)dfs(init);
    for (int i = 0; i < x; i++)
      cout << "myon";
    cout << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;

int N;

vector<int> mem;
vector<int> mas;

vector<int> item[25];

int w[16];
int h[16];
int a[4][4];

map<int, char> memo;

char dfs(int bit) {
  if (bit == 0)
    return 0;
  // if( ~memo[bit] ) return memo[bit];
  if (memo.count(bit))
    return memo[bit];

  char ans = 30;

  for (int p = 0; p < 25; p++) {
    if (bit >> p & 1) {
      for (int i = 0; i < item[p].size(); i++)
        ans = min(ans, (char)(dfs(bit ^ item[p][i]) + 1));
      break;
    }
  }
  return memo[bit] = ans;
}

int main() {
  // memset(memo,-1,sizeof(memo));

  for (int w = 1; w <= 5; w++) {
    for (int h = 1; h <= 5; h++) {
      for (int i = 0; i <= 5 - h; i++) {
        for (int j = 0; j <= 5 - w; j++) {
          int mask = 0;
          for (int k = 0; k < h; k++)
            for (int l = 0; l < w; l++)
              mask |= (1 << ((i + k) * 5 + j + l));
          // cout << init << " " << mask << endl;
          item[i * 5 + j].push_back(mask);
        }
      }
    }
  }
  while (cin >> N && N) {
    int init = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        int c = 0;
        cin >> c;
        init |= (c << (i * 5 + j));
      }
    }
    // cout << init << endl;
    int x = (int)dfs(init);
    for (int i = 0; i < x; i++)
      cout << "myon";
    cout << endl;
  }
}
Problem p00645 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
#define MAX_N (5)
int n;
char memo[1 << 25];
int sq[6][6];
int dfs(int bit) {
  if (~memo[bit]) {
    return memo[bit];
  }
  int ans = (1 << 25);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (bit >> (i * MAX_N + j) & 1) {
        for (int s1 = 1; s1 <= n - i; s1++)
          for (int s2 = 1; s2 <= n - j; s2++)
            ans = min(ans, 1 + dfs(bit ^ (sq[s1][s2] << (i * MAX_N + j))));
        goto endfunction;
      }
    }
  }
endfunction:
  return memo[bit] = ans;
}
int gen(int x, int y) {
  int ans = 0;
  for (int i = 0; i < y; i++)
    for (int j = 0; j < x; j++)
      ans |= 1 << (i * MAX_N + j);
  return ans;
}
int main() {
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++)
      sq[i][j] = gen(j, i);
  memset(memo, -1, sizeof(memo));
  memo[0] = 0;

  while (cin >> n, n) {
    int bit = 0, a;

    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        cin >> a, bit |= a << (i * MAX_N + j);
    int r = dfs(bit);
    for (int i = 0; i < r; i++)
      cout << "myon";
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
#define MAX_N (5)
int n;
char memo[1 << 25];
int sq[6][6];
int dfs(int bit) {
  if (~memo[bit]) {
    return memo[bit];
  }
  int ans = (1 << 25);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (bit >> (i * MAX_N + j) & 1) {
        for (int s1 = 1; s1 <= n - i; s1++)
          for (int s2 = 1; s2 <= n - j; s2++)
            ans = min(ans, 1 + dfs(bit ^ (sq[s1][s2] << (i * MAX_N + j))));
        break;
      }
    }
  }
  return memo[bit] = ans;
}
int gen(int x, int y) {
  int ans = 0;
  for (int i = 0; i < y; i++)
    for (int j = 0; j < x; j++)
      ans |= 1 << (i * MAX_N + j);
  return ans;
}
int main() {
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++)
      sq[i][j] = gen(j, i);
  memset(memo, -1, sizeof(memo));
  memo[0] = 0;

  while (cin >> n, n) {
    int bit = 0, a;

    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        cin >> a, bit |= a << (i * MAX_N + j);
    int r = dfs(bit);
    for (int i = 0; i < r; i++)
      cout << "myon";
    cout << endl;
  }
}
Problem p00645 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#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;

vector<vector<unsigned>> change(25);
vector<char> memo(1 << 25, -1);

int solve(unsigned enemy) {
  if (enemy == 0)
    return 0;
  if (memo[enemy] != -1)
    return memo[enemy];

  int k = 0;
  while (!(enemy & (1 << k)))
    ++k;

  int ret = INT_MAX;
  for (unsigned i = 0; i < change[k].size(); ++i) {
    unsigned next = enemy ^ change[k][i];
    ret = min(ret, solve(next) + 1);
  }

  return memo[enemy] = ret;
}

int main() {
  for (int i = 0; i < 25; ++i) {
    for (int j = i / 5; j < 5; ++j) {
      for (int k = i % 5; k < 5; ++k) {
        bitset<25> bs;
        for (int y = i / 5; y <= j; ++y) {
          for (int x = i % 5; x <= k; ++x) {
            bs[y * 5 + x] = true;
          }
        }
        change[i].push_back(bs.to_ulong());
      }
    }
  }

  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    bitset<25> enemy;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        char tmp;
        cin >> tmp;
        if (tmp == '1')
          enemy[i * 5 + j] = true;
      }
    }

    int m = solve(enemy.to_ulong());
    string ret;
    while (--m >= 0)
      ret += "myon";
    cout << ret << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#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;

vector<vector<unsigned>> change(25);
vector<char> memo;

int solve(unsigned enemy) {
  if (enemy == 0)
    return 0;
  if (memo[enemy] != -1)
    return memo[enemy];

  int k = 0;
  while (!(enemy & (1 << k)))
    ++k;

  int ret = INT_MAX;
  for (unsigned i = 0; i < change[k].size(); ++i) {
    unsigned next = enemy ^ change[k][i];
    ret = min(ret, solve(next) + 1);
  }

  return memo[enemy] = ret;
}

int main() {
  for (int i = 0; i < 25; ++i) {
    for (int j = i / 5; j < 5; ++j) {
      for (int k = i % 5; k < 5; ++k) {
        bitset<25> bs;
        for (int y = i / 5; y <= j; ++y) {
          for (int x = i % 5; x <= k; ++x) {
            bs[y * 5 + x] = true;
          }
        }
        change[i].push_back(bs.to_ulong());
      }
    }
  }

  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;

    bitset<25> enemy;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        char tmp;
        cin >> tmp;
        if (tmp == '1')
          enemy[i * 5 + j] = true;
      }
    }

    memo.assign(1 << 25, -1);
    int m = solve(enemy.to_ulong());
    string ret;
    while (--m >= 0)
      ret += "myon";
    cout << ret << endl;
  }
}
Problem p00645 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, f[5][5], s;
int dp[1 << 20];

int rec(int at) {
  if (at == 5)
    return dp[s >> 5];
  if ((s & (1 << at)) == 0)
    return rec(at + 1);
  int ans = 1 << 30;
  rep(xe, 5) for (int ye = at; ye < 5; ye++) {
    rep(x, xe + 1) for (int y = at; y <= ye; y++) s ^= 1 << (x * 5 + y);
    ans = min(ans, rec(at + 1) + 1);
    rep(x, xe + 1) for (int y = at; y <= ye; y++) s ^= 1 << (x * 5 + y);
  }
  return ans;
}

int main() {
  rep(i, 1 << 20) dp[i] = 1 << 30;
  dp[0] = 0;
  rep(b, 1 << 20) {
    rep(xe, 4) rep(xs, xe + 1) rep(ye, 5) rep(ys, ye + 1) {
      int nb = b;
      for (int x = xs; x <= xe; x++)
        for (int y = ys; y <= ye; y++) {
          nb ^= 1 << (x * 5 + y);
        }
      dp[nb] = min(dp[nb], dp[b] + 1);
    }
  }
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    memset(f, 0, sizeof(f));
    rep(i, n) rep(j, n) scanf("%d", f[i] + j);
    s = 0;
    rep(i, n) rep(j, n) s |= f[i][j] << (i * 5 + j);
    int ans = n < 5 ? dp[s] : rec(0);
    rep(i, ans) printf("myon");
    putchar('\\n');
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, f[5][5], s;
int dp[1 << 20];

int rec(int at) {
  if (at == 5)
    return dp[s >> 5];
  if ((s & (1 << at)) == 0)
    return rec(at + 1);
  int ans = 1 << 30;
  for (int ye = at; ye < 5; ye++)
    rep(xe, 5) {
      for (int x = at; x <= xe; x++)
        for (int y = 0; y <= ye; y++)
          s ^= 1 << (x * 5 + y);
      ans = min(ans, rec(at + 1) + 1);
      for (int x = at; x <= xe; x++)
        for (int y = 0; y <= ye; y++)
          s ^= 1 << (x * 5 + y);
    }
  return ans;
}

int main() {
  rep(i, 1 << 20) dp[i] = 1 << 30;
  dp[0] = 0;
  rep(b, 1 << 20) {
    rep(xe, 4) rep(xs, xe + 1) rep(ye, 5) rep(ys, ye + 1) {
      int nb = b;
      for (int x = xs; x <= xe; x++)
        for (int y = ys; y <= ye; y++) {
          nb ^= 1 << (x * 5 + y);
        }
      dp[nb] = min(dp[nb], dp[b] + 1);
    }
  }
  fprintf(stderr, "ready\\n");
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    memset(f, 0, sizeof(f));
    rep(i, n) rep(j, n) scanf("%d", f[i] + j);
    s = 0;
    rep(i, n) rep(j, n) s |= f[i][j] << (i * 5 + j);
    int ans = n < 5 ? dp[s] : rec(0);
    rep(i, ans) printf("myon");
    putchar('\\n');
  }
}