Problem p00026 (C++) — buggy submission, verdict: Runtime Error

// compile in C++11. use -std=c++11.
#include <algorithm>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>

// this require C++11
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

template <typename T> T input() {
  T t;
  cin >> t;
  return t;
}

template <typename T> vector<T> input(const int N) {
  vector<T> v(N);
  repeat(i, N) cin >> v[i];
  return v;
}

int main() {
  const int FIELD_SIZE = 10;
  const int PADDING = 2;
  const int DATA_SIZE = FIELD_SIZE + 2 * PADDING;
  vector<vi> field(DATA_SIZE, vi(DATA_SIZE));
  {
    int y, x, size;
    char comma;
    while (cin >> x >> comma >> y >> comma >> size) {
      x += PADDING;
      y += PADDING;

      field[y][x] += 1;
      vi dx, dy;
      if (size == 1) {
        dx = {1, 0, -1, 0};
        dy = {0, -1, 0, 1};
      } else {
        for (int i = -1; i <= 1; i++) {
          for (int j = -1; j <= 1; j++) {
            if (i == 0 and j == 0)
              continue;
            dx.push_back(i);
            dy.push_back(j);
          }
        }
        if (size == 3) {
          vi ax = {2, 0, -2, 0};
          vi ay = {0, -2, 0, 2};
          repeat(i, 4) {
            dx.push_back(ax[i]);
            dy.push_back(ay[i]);
          }
        }
      }
      repeat(i, dx.size()) { field[y + dy[i]][x + dx[i]]++; }
    }
  }

  int maxi = -1;
  int no = 0;

  for (int y = PADDING; y < FIELD_SIZE + PADDING; y++) {
    for (int x = PADDING; x < FIELD_SIZE + PADDING; x++) {
      maxi = max(maxi, field[y][x]);
      no += field[y][x] == 0;
    }
  }

  cout << no << endl << maxi << endl;

  return 0;
}

Error: 0
dx=[-1,-1,-1,0,0,1,1,1,2,0,-2,0,] (L:96)
dy=[-1,0,1,-1,1,-1,0,1,0,-2,0,2,] (L:97)
dx=[1,0,-1,0,] (L:96)
dy=[0,-1,0,1,] (L:97)
dx=[-1,-1,-1,0,0,1,1,1,] (L:96)
dy=[-1,0,1,-1,1,-1,0,1,] (L:97)
dx=[-1,-1,-1,0,0,1,1,1,] (L:96)
dy=[-1,0,1,-1,1,-1,0,1,] (L:97)
dx=[-1,-1,-1,0,0,1,1,1,2,0,-2,0,] (L:96)
dy=[-1,0,1,-1,1,-1,0,1,0,-2,0,2,] (L:97)
dx=[1,0,-1,0,] (L:96)
dy=[0,-1,0,1,] (L:97)
0000000000
0000000000
0000000000
0031100000
0235210000
1145410000
0234320000
0022100000
0001000000
0000000000


Fixed submission:

// compile in C++11. use -std=c++11.
#include <algorithm>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>

// this require C++11
#include <random>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

template <typename T> T input() {
  T t;
  cin >> t;
  return t;
}

template <typename T> vector<T> input(const int N) {
  vector<T> v(N);
  repeat(i, N) cin >> v[i];
  return v;
}

int main() {
  const int FIELD_SIZE = 10;
  const int PADDING = 2;
  const int DATA_SIZE = FIELD_SIZE + 2 * PADDING;
  vector<vi> field(DATA_SIZE, vi(DATA_SIZE));
  {
    int y, x, size;
    char comma;
    while (cin >> x >> comma >> y >> comma >> size) {
      x += PADDING;
      y += PADDING;

      field[y][x] += 1;
      vi dx, dy;
      if (size == 1) {
        dx = {1, 0, -1, 0};
        dy = {0, -1, 0, 1};
      } else {
        for (int i = -1; i <= 1; i++) {
          for (int j = -1; j <= 1; j++) {
            if (i == 0 and j == 0)
              continue;
            dx.push_back(i);
            dy.push_back(j);
          }
        }
        if (size == 3) {
          vi ax = {2, 0, -2, 0};
          vi ay = {0, -2, 0, 2};
          repeat(i, 4) {
            dx.push_back(ax[i]);
            dy.push_back(ay[i]);
          }
        }
      }
      dump(dx);
      dump(dy);
      repeat(i, dx.size()) { field[y + dy[i]][x + dx[i]]++; }
    }
  }

  int maxi = -1;
  int no = 0;

  for (int y = PADDING; y < FIELD_SIZE + PADDING; y++) {
    for (int x = PADDING; x < FIELD_SIZE + PADDING; x++) {
      cerr << field[y][x];
      maxi = max(maxi, field[y][x]);
      no += field[y][x] == 0;
    }
    cerr << endl;
  }

  cout << no << endl << maxi << endl;

  return 0;
}