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

#include <iostream>
using namespace std;
int main() {
  int a = 0, b, c, d, n, h = 0, jo, ko, i, p[100] = {0};
  cin >> n;
  for (i = 0; i < n; i++) {
    a = 0;
    cin >> jo >> ko;
    h = 0;
    while (jo != ko) {
      if (jo == 9 && ko == 5) {
        p[h] = jo;
        h++;
        break;
      }
      if (jo == 0 && ko != 0) {
        p[h] = jo;
        jo++;
        h++;
        a = 0;
      }
      if (jo > ko && jo < 6) {
        p[h] = jo;
        jo--;
        h++;
      }
      if (jo > ko && jo >= 6) {
        if (jo <= 9) {
          p[h] = jo;
          jo++;
          h++;
        }
        if (jo > 9) {
          jo = 5;
          p[h] = jo;
          jo--;
          h++;
          a = 1;
        }
      }
      if (jo < ko && a != 1) {
        p[h] = jo;
        jo++;
        h++;
      }
      if (jo < ko && a == 1) {
        p[h] = jo;
        jo--;
        h++;
      }
    }
    for (d = 0; d < h; d++) {
      cout << p[d] << " ";
    }
    cout << ko << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a = 0, b, c, d, n, h = 0, jo, ko, i, p[100] = {0};
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> jo >> ko;
    h = 0;
    for (c = 0; c < 11; c++) {
      p[c] = 0;
    }
    while (jo != ko) {
      if (jo <= 5) {
        if (jo == 0 && ko != 0) {
          p[h] = jo;
          jo++;
          h++;
        }
        if (jo < ko && jo != 0) {
          p[h] = jo;
          jo++;
          h++;
        }
        if (jo > ko) {
          p[h] = jo;
          jo--;
          h++;
        }
      }
      if (jo > 5) {
        if (jo < ko) {
          p[h] = jo;
          jo++;
          h++;
        }
        if (jo > ko) {
          if (jo <= 9) {
            p[h] = jo;
            jo++;
            h++;
          }
          if (jo > 9 && ko < 5) {
            jo = 5;
            p[h] = jo;
            jo--;
            h++;
          }
          if (jo > 9 && ko > 5) {
            jo = 5;
            p[h] = jo;
            jo++;
            h++;
          }
        }
      }
    }
    for (d = 0; d < h; d++) {
      cout << p[d] << " ";
    }
    cout << ko << endl;
  }
}
Problem p00140 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

void f(int a, int b) {
  cout << a;
  if (a == b) {
    cout << endl;
    return;
  }
  if (6 <= a && a <= 8) {
    a++;
  } else if (a == 9) {
    a = 5;
  } else if (a < b) {
    a++;
  } else {
    a--;
  }
  cout << " ";
  f(a, b);
}

int main() {
  int n = in();
  int a, b;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    if (6 <= b && b < a) {
      if (b == 6 && a == 7)
        cout << "7 8 9 5 4 3 2 1 0 1 2 3 4 5 6" << endl;
      if (b == 6 && a == 8)
        cout << "8 9 5 4 3 2 1 0 1 2 3 4 5 6" << endl;
      if (b == 6 && a == 9)
        cout << "9 5 4 3 2 1 0 1 2 3 4 5 6" << endl;
      if (b == 7 && a == 8)
        cout << "8 9 5 4 3 2 1 0 1 2 3 4 5 6 7" << endl;
      if (b == 7 && a == 9)
        cout << "9 5 4 3 2 1 0 1 2 3 4 5 6 7" << endl;
      if (b == 8 && a == 9)
        cout << "9 5 4 3 2 1 0 1 2 3 4 5 6 7 8" << endl;
    } else {
      f(a, b);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

void f(int a, int b) {
  cout << a;
  if (a == b) {
    cout << endl;
    return;
  }
  if (5 <= a && a <= 8) {
    a++;
  } else if (a == 9) {
    a = 5;
  } else if (a < b) {
    a++;
  } else {
    a--;
  }
  cout << " ";
  f(a, b);
}

int main() {
  int n = in();
  int a, b;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    f(a, b);
  }
  return 0;
}
Problem p00140 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

int busstop[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4,
                 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int main() {
  int n;
  cin >> n;
  for (int k = 0; k < n; k++) {

    int e1, e2;
    bool isFirst = false;
    cin >> e1 >> e2;

    if (e1 > e2)
      isFirst = true;

    for (int i = 0;; i++) {
      if (busstop[i] == e1) {
        if (isFirst) {
          isFirst = !isFirst;
          continue;
        }
        for (int j = i;; j++) {
          if (busstop[j] == e2) {
            cout << " " << busstop[j];
            goto end_state;
          } else {
            if (j == i)
              cout << busstop[j];
            else
              cout << " " << busstop[j];
          }
        }
      }
    }
  end_state:
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

int busstop[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3,
                 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int main() {
  int n;
  cin >> n;
  for (int k = 0; k < n; k++) {

    int e1, e2;
    bool isFirst = false;
    cin >> e1 >> e2;

    if (e1 > e2)
      isFirst = true;

    for (int i = 0;; i++) {
      if (busstop[i] == e1) {
        if (isFirst) {
          isFirst = !isFirst;
          continue;
        }
        for (int j = i;; j++) {
          if (busstop[j] == e2) {
            cout << " " << busstop[j];
            goto end_state;
          } else {
            if (j == i)
              cout << busstop[j];
            else
              cout << " " << busstop[j];
          }
        }
      }
    }
  end_state:
    cout << endl;
  }
}
Problem p00140 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back
#define p(a, b) g.PB(pii(a, b))
#define INF (1 << 29)

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
  vp g; // pos to
  REP(i, 9) p(i, i + 1);
  p(9, 10);
  REP(i, 4) p(5 - i, i + 11);
  p(1, 0);

  int n;
  cin >> n;
  while (n--) {
    int prev[2][20], miner[2], tmp[2];
    int a, b;
    scanf("%d %d", &a, &b);

    tmp[0] = tmp[1] = INF;
    REP(i, g.size()) if (g[i].first == a) {
      if (tmp[0] == INF)
        tmp[0] = i;
      else
        tmp[1] = i;
    }

    miner[0] = miner[1] = INF;
    REP(i, 2) {
      if (tmp[i] == INF)
        break;

      queue<int> que; // pos
      que.push(tmp[i]);

      miner[i] = 0;
      while (true) {
        int pos = g[que.front()].first;
        int to = g[que.front()].second;
        que.pop();

        prev[i][miner[i]++] = pos;
        if (pos == b)
          break;

        que.push(to);
      }
    }

    int ans = miner[0] < miner[1] ? 0 : 1;
    REP(i, miner[ans]) {
      if (i != 0)
        printf(" ");
      printf("%d", prev[ans][i]);
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back
#define p(a, b) g.PB(pii(a, b))
#define INF (1 << 29)

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
  vp g; // pos to
  REP(i, 9) p(i, i + 1);
  p(9, 10);
  REP(i, 4) p(5 - i, i + 11);
  p(1, 0);

  int n;
  cin >> n;
  while (n--) {
    int prev[2][10], miner[2], tmp[2];
    int a, b;
    scanf("%d %d", &a, &b);

    tmp[0] = tmp[1] = INF;
    REP(i, g.size()) if (g[i].first == a) {
      if (tmp[0] == INF)
        tmp[0] = i;
      else
        tmp[1] = i;
    }

    miner[0] = miner[1] = INF;
    REP(i, 2) {
      if (tmp[i] == INF)
        break;

      queue<int> que; // pos
      que.push(tmp[i]);

      miner[i] = 0;
      while (true) {
        int pos = g[que.front()].first;
        int to = g[que.front()].second;
        que.pop();

        prev[i][miner[i]++] = pos;
        if (pos == b)
          break;

        que.push(to);
      }
    }

    int ans = miner[0] < miner[1] ? 0 : 1;
    REP(i, miner[ans]) {
      if (i != 0)
        printf(" ");
      printf("%d", prev[ans][i]);
    }
    cout << endl;
  }
  return 0;
}
Problem p00141 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int d;
  cin >> d;
  const int POS[][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
  while (d--) {
    int n;
    cin >> n;
    vector<vector<char>> field(n + 2);
    for (int i = 0; i <= n + 1; ++i) {
      field[i].reserve(n + 2);
      for (int j = 0; j <= n + 1; ++j)
        field[i][j] = (i == n + 1 || j == n + 1) ? 1 : 0;
    }
    int x = 0, y = n - 1, p = 0;
    for (;;) {
      if (x < 0 || y < 0)
        break;
      int dx = POS[p][0], dy = POS[p][1];
      int px = POS[(p + 4 + 1) % 4][0], py = POS[(p + 4 + 1) % 4][1],
          qx = POS[(p + 4 - 1) % 4][0], qy = POS[(p + 4 - 1) % 4][1];
      field[y][x] = 1;
      x += dx, y += dy;
      if (y == 0 && x == 0 || (y + 2 * dy >= 0 && x + 2 * dx >= 0 &&
                               field[y + 2 * dy][x + 2 * dx] == 1))
        p = (p + 1) % 4;
      if ((y + dy + py >= 0 && x + dx + px >= 0 &&
           field[y + dy + py][x + dx + px] == 1) ||
          (y + dy + qy >= 0 && x + dx + qx >= 0 &&
           field[y + dy + qy][x + dx + qx] == 1))
        break;
    }
    if (n == 2)
      field[1][1] = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
        cout << ((field[i][j]) ? '#' : ' ');
      cout << endl;
    }
    if (d)
      cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int d;
  cin >> d;
  const int POS[][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
  while (d--) {
    int n;
    cin >> n;
    vector<vector<char>> field(n + 2);
    for (int i = 0; i <= n + 1; ++i) {
      field[i].reserve(n + 2);
      for (int j = 0; j <= n + 1; ++j)
        field[i][j] = (i == n + 1 || j == n + 1) ? 1 : 0;
    }
    int x = 0, y = n - 1, p = 0;
    for (;;) {
      int dx = POS[p][0], dy = POS[p][1];
      int px = POS[(p + 4 + 1) % 4][0], py = POS[(p + 4 + 1) % 4][1],
          qx = POS[(p + 4 - 1) % 4][0], qy = POS[(p + 4 - 1) % 4][1];
      field[y][x] = 1;
      x += dx, y += dy;
      if (y == 0 && x == 0 || (y + 2 * dy >= 0 && x + 2 * dx >= 0 &&
                               field[y + 2 * dy][x + 2 * dx] == 1))
        p = (p + 1) % 4;
      if ((y + dy + py >= 0 && x + dx + px >= 0 &&
           field[y + dy + py][x + dx + px] == 1) ||
          (y + dy + qy >= 0 && x + dx + qx >= 0 &&
           field[y + dy + qy][x + dx + qx] == 1))
        break;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
        cout << ((field[i][j]) ? '#' : ' ');
      cout << endl;
    }
  }
  return 0;
}
Problem p00141 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  const int N = 100;
  char a[N][N];

  int n, d, caseCount = 0, i, j, x, y, dd[] = {-1, 0, 1, 0}, angle, c;
  scanf("%d", &d);
  while (d--) {
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
      for (j = 0; j < n; ++j)
        a[i][j] = ' ';

    x = 0;
    y = n - 1;
    angle = 0;
    for (c = 0; c < 3; ++c) {
      for (; x >= 0 && y >= 0 && x < n && y < n;
           x += dd[(angle + 1) % 4], y += dd[angle]) {
        a[y][x] = '#';
      }
      x -= dd[(angle + 1) % 4];
      y -= dd[angle];
      angle = (angle + 1) % 4;
      ;
    }
    if (n > 2) {
      for (; n;) {
        c = 0;
        for (; a[y + 2 * dd[angle]][x + 2 * dd[(angle + 1) % 4]] != '#';
             x += dd[(angle + 1) % 4], y += dd[angle])
          a[y][x] = '#', c++;
        if (c < 2)
          break;
        angle = (angle + 1) % 4;
        ;
      }
      a[y][x] = '#';
    } else if (n == 2)
      a[n - 1][n - 1] = ' ';

    printf("%s", (caseCount++ ? "\\n" : ""));
    for (i = 0; i < n; ++i) {
      for (j = 0; j < n; ++j)
        putchar(a[i][j]);
      putchar('\\n');
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  const int N = 127;
  char a[N][N];

  int n, d, caseCount = 0, i, j, x, y, dd[] = {-1, 0, 1, 0}, angle, c;
  scanf("%d", &d);
  while (d--) {
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
      for (j = 0; j < n; ++j)
        a[i][j] = ' ';

    x = 0;
    y = n - 1;
    angle = 0;
    for (c = 0; c < 3; ++c) {
      for (; x >= 0 && y >= 0 && x < n && y < n;
           x += dd[(angle + 1) % 4], y += dd[angle]) {
        a[y][x] = '#';
      }
      x -= dd[(angle + 1) % 4];
      y -= dd[angle];
      angle = (angle + 1) % 4;
      ;
    }
    for (;;) {
      c = 0;
      for (; a[y + 2 * dd[angle]][x + 2 * dd[(angle + 1) % 4]] != '#';
           x += dd[(angle + 1) % 4], y += dd[angle])
        a[y][x] = '#', c++;
      if (c < 2)
        break;
      angle = (angle + 1) % 4;
      ;
    }
    a[y][x] = '#';

    printf("%s", (caseCount++ ? "\\n" : ""));
    for (i = 0; i < n; ++i) {
      for (j = 0; j < n; ++j)
        putchar(a[i][j]);
      putchar('\\n');
    }
  }
  return 0;
}
Problem p00141 (C++) — buggy submission, verdict: Time Limit Exceeded

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

char a[102][102];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

int main() {
  bool fst = true;
  int n;
  cin >> n;
  while (n--) {
    memset(a, ' ', sizeof(a));
    int m, y, x, dir;
    cin >> m;
    if (m == 1) {
      if (!fst)
        cout << endl;
      cout << "#\\n";
      fst = false;
      continue;
    }
    y = m;
    x = 1;
    dir = 0;
    a[y][x] = '#';
    while (1) {
      for (int i = 0; i < m - 1; i++) {
        if (a[y + 2 * dy[dir]][x + 2 * dx[dir]] == '#')
          break;
        y += dy[dir];
        x += dx[dir];
        a[y][x] = '#';
      }
      dir = (dir + 1) % 4;
      if (a[y + 2 * dy[dir]][x + 2 * dx[dir]] == '#')
        break;
      if (a[y - 1][x - 1] == '#' || a[y - 1][x + 1] == '#' ||
          a[y + 1][x - 1] == '#' || a[y + 1][x + 1] == '#')
        break;
    }
    if (!fst)
      cout << endl;
    fst = false;
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++)
        cout << a[i][j];
      cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

char a[102][102];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

int main() {
  bool fst = true;
  int n;
  cin >> n;
  while (n--) {
    memset(a, ' ', sizeof(a));
    int m, y, x, dir;
    cin >> m;
    y = m;
    x = 1;
    dir = 0;
    a[y][x] = '#';
    while (1) {
      for (int i = 0; i < m - 1; i++) {
        if (a[y + 2 * dy[dir]][x + 2 * dx[dir]] == '#')
          break;
        y += dy[dir];
        x += dx[dir];
        a[y][x] = '#';
      }
      dir = (dir + 1) % 4;
      if (a[y + 2 * dy[dir]][x + 2 * dx[dir]] == '#')
        break;
      if (a[y - 1][x - 1] == '#' || a[y - 1][x + 1] == '#' ||
          a[y + 1][x - 1] == '#' || a[y + 1][x + 1] == '#')
        break;
    }
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++)
        cout << a[i][j];
      cout << endl;
    }
    if (!fst)
      cout << endl;
    fst = false;
  }
  return 0;
}
Problem p00141 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
bool vis[110][110], na[110][110];
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int ex[] = {-1, 1, 0, 0}, ey[] = {0, 0, -1, 1};
int n;
void DFS(int y, int x, int k) {
  vis[y][x] = true;
  na[y][x] = true;
  int xx, yy;
  bool done = false;
  for (int i = 0; i < 4; i++) {
    xx = x + dx[k], yy = y + dy[k];
    bool ok = false;
    if (0 <= xx && xx < n && 0 <= yy && yy < n) {
      if (na[yy][xx] == false) {
        ok = true;
      }
    }
    if (ok) {
      done = true;
      break;
    }
    k = (k + 1) % 4;
  }
  if (!done)
    return;
  for (int i = 0; i < 2; i++) {
    int r = i + (k % 2) * 2;
    int nx = x + ex[r], ny = y + ey[r];
    if (0 <= nx && nx < n && 0 <= ny && ny < n) {
      na[ny][nx] = true;
    }
  }
  DFS(yy, xx, k);
}
int main() {
  int q;
  cin >> q;
  for (int u = 0; u < q; u++) {
    if (u)
      cout << endl;
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        vis[i][j] = false;
        na[i][j] = false;
      }
    }
    DFS(n - 1, 0, 0);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        cout << (vis[i][j] ? "#" : " ");
      cout << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
bool vis[30][30], na[30][30];
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int ex[] = {-1, 1, 0, 0}, ey[] = {0, 0, -1, 1};
int n;
void DFS(int y, int x, int k) {
  vis[y][x] = true;
  na[y][x] = true;
  int xx, yy;
  bool done = false;
  for (int i = 0; i < 4; i++) {
    xx = x + dx[k], yy = y + dy[k];
    bool ok = false;
    if (0 <= xx && xx < n && 0 <= yy && yy < n) {
      if (na[yy][xx] == false) {
        ok = true;
      }
    }
    if (ok) {
      done = true;
      break;
    }
    k = (k + 1) % 4;
  }
  if (!done)
    return;
  for (int i = 0; i < 2; i++) {
    int r = i + (k % 2) * 2;
    int nx = x + ex[r], ny = y + ey[r];
    if (0 <= nx && nx < n && 0 <= ny && ny < n) {
      na[ny][nx] = true;
    }
  }
  DFS(yy, xx, k);
}
int main() {
  int q;
  cin >> q;
  for (int u = 0; u < q; u++) {
    if (u)
      cout << endl;
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        vis[i][j] = false;
        na[i][j] = false;
      }
    }
    DFS(n - 1, 0, 0);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        cout << (vis[i][j] ? "#" : " ");
      cout << endl;
    }
  }
  return 0;
}
Problem p00141 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
char buf[150][150];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool check(int tx, int ty) {
  if (tx < 0 || ty < 0)
    return false;
  return buf[tx][ty] == '#';
}
void solve(int x) {
  memset(buf, ' ', sizeof(buf));
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= x; j++) {
      buf[i][j] = '#';
    }
  }
  int X = x, Y = 2;
  int cnt = 0;
  for (int p = 0; p <= 10000; p++) {
    if (X > x + 10 || Y > x + 10 || X < 0 || Y < 0)
      break;
    if (x % 4 == 1 && X == (x + 3) / 2 && Y == (x + 1) / 2)
      break;
    if (x % 4 == 3 && X == (x + 1) / 2 && Y == (x + 3) / 2)
      break;
    buf[X][Y] = ' ';
    X += dx[cnt];
    Y += dy[cnt];
    if (check(X + dx[cnt], Y + dy[cnt]) &&
        !check(X + dx[cnt] * 2, Y + dy[cnt] * 2)) {
      cnt++;
      cnt %= 4;
    }
  }
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= x; j++) {
      cout << buf[i][j];
    }
    cout << endl;
  }
  return;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    if (k == 2) {
      cout << "##" << endl;
      cout << "# " << endl;
    } else
      solve(k);
    if (i != q - 1)
      cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
char buf[150][150];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool check(int tx, int ty) {
  if (tx < 0 || ty < 0)
    return false;
  return buf[tx][ty] == '#';
}
void solve(int x) {
  memset(buf, ' ', sizeof(buf));
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= x; j++) {
      buf[i][j] = '#';
    }
  }
  int X = x, Y = 2;
  int cnt = 0;
  for (int p = 0; p <= 10000; p++) {
    if (x % 4 == 1 && X == (x + 3) / 2 && Y == (x + 1) / 2)
      break;
    if (x % 4 == 3 && X == (x + 1) / 2 && Y == (x + 3) / 2)
      break;
    buf[X][Y] = ' ';
    X += dx[cnt];
    Y += dy[cnt];
    if (check(X + dx[cnt], Y + dy[cnt]) &&
        !check(X + dx[cnt] * 2, Y + dy[cnt] * 2)) {
      cnt++;
      cnt %= 4;
    }
  }
  for (int i = 1; i <= x; i++) {
    for (int j = 1; j <= x; j++) {
      cout << buf[i][j];
    }
    cout << endl;
  }
  return;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    solve(k);
  }
  return 0;
}