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

#include <algorithm>
#include <cstdio>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int p[10][10];
int cnt = 0, Max = 0;
void ink(int x, int y) {
  if (0 <= x && x < 10 && 0 <= y && y < 10)
    p[x][y]++;
}

int main() {

  rep(i, 10) rep(j, 10) { p[i][j] = 0; }
  int x, y, size;
  while (~scanf("%d,%d,%d", &x, &y, &size)) {

    if (size == 1) {
      ink(x, y);
      ink(x + 1, y);
      ink(x - 1, y);
      ink(x, y + 1);
      ink(x, y - 1);
    } else if (size == 2) {
      ink(x, y);
      ink(x + 1, y);
      ink(x - 1, y);
      ink(x, y + 1);
      ink(x, y - 1);
      ink(x + 1, y + 1);
      ink(x - 1, y + 1);
      ink(x - 1, y - 1);
      ink(x + 1, y - 1);
    } else if (size == 3) {
      ink(x, y);
      ink(x + 1, y);
      ink(x - 1, y);
      ink(x, y + 1);
      ink(x, y - 1);
      ink(x + 1, y + 1);
      ink(x - 1, y + 1);
      ink(x - 1, y - 1);
      ink(x + 1, y - 1);
      ink(x + 2, y);
      ink(x - 2, y);
      ink(x, y + 2);
      ink(x, y - 2);
    }
    cnt = 0;
    Max = -10000000;
    rep(i, 10) rep(j, 10) {
      if (p[i][j] == 0)
        cnt++;
      Max = max(Max, p[i][j]);
    }
  }
  cout << cnt << "\\n" << Max << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int p[10][10];
int cnt = 0, Max = 0;
void ink(int x, int y) {
  if (0 <= x && x < 10 || 0 <= y && y < 10)
    p[x][y]++;
}

int main() {

  rep(i, 10) rep(j, 10) { p[i][j] = 0; }

  while (1) {

    int x, y, size;

    scanf("%d,%d,%d", &x, &y, &size);
    if (cin.eof())
      break;
    if (size == 1) {
      ink(x, y);
      ink(x + 1, y);
      ink(x - 1, y);
      ink(x, y + 1);
      ink(x, y - 1);
    } else if (size == 2) {
      ink(x, y);
      ink(x + 1, y);
      ink(x - 1, y);
      ink(x, y + 1);
      ink(x, y - 1);
      ink(x + 1, y + 1);
      ink(x - 1, y + 1);
      ink(x - 1, y - 1);
      ink(x + 1, y - 1);
    } else if (size == 3) {
      ink(x, y);
      ink(x + 1, y);
      ink(x - 1, y);
      ink(x, y + 1);
      ink(x, y - 1);
      ink(x + 1, y + 1);
      ink(x - 1, y + 1);
      ink(x - 1, y - 1);
      ink(x + 1, y - 1);
      ink(x + 2, y);
      ink(x - 2, y);
      ink(x, y + 2);
      ink(x, y - 2);
    }
    cnt = Max = 0;
    rep(i, 10) rep(j, 10) {
      if (p[i][j] == 0)
        cnt++;
      Max = max(Max, p[i][j]);
    }
  }
  cout << cnt << "\\n" << Max << endl;

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

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int i, j, k, l, m, n, o, x, y, z;
  int max = 0;
  int count = 0;
  vector<vector<int>> s;
  s.resize(14);
  for (i = 0; i < 14; i++) {
    s[i].resize(14);
  }
  for (j = 0; j < 14; j++) {
    for (k = 0; k < 14; k++) {
      s[j][k] = 0;
    }
  }
  while (scanf("%d,%d,%d", &x, &y, &z) != EOF) {
    if (z == 1) {
      s[x + 2][y + 2] += 1;
      s[x + 1][y + 2] += 1;
      s[x + 3][y + 2] += 1;
      s[x + 2][y + 1] += 1;
      s[x + 2][y + 3] += 1;
    } else if (z == 2) {
      for (l = x + 1; l <= x + 3; l++) {
        for (m = y + 1; m <= y + 3; m++) {
          s[l][m] += 1;
        }
      }
    } else if (z == 3) {
      for (l = x + 1; l <= x + 3; l++) {
        for (m = y + 1; m <= y + 3; m++) {
          s[l][m] += 1;
        }
      }
      s[x][y + 2] += 1;
      s[x + 4][y + 2] += 1;
      s[x + 2][y] += 1;
      s[x + 2][y + 4] += 1;
    }
  }
  for (n = 2; n < 12; n++) {
    for (o = 2; o < 12; o++) {
      if (max < s[n][o]) {
        max = s[n][o];
      }
      if (s[n][o] == 0) {
        count += 1;
      }
    }
  }
  cout << count << endl;
  cout << max << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int i, j, k, l, m, n, o, x, y, z;
  int max = 0;
  int count = 0;
  vector<vector<int>> s;
  s.resize(10);
  for (i = 0; i < 14; i++) {
    s[i].resize(14);
  }
  for (j = 0; j < 14; j++) {
    for (k = 0; k < 14; k++) {
      s[j][k] = 0;
    }
  }
  while (scanf("%d,%d,%d", &x, &y, &z) != EOF) {
    if (z == 1) {
      s[x + 2][y + 2] += 1;
      s[x + 1][y + 2] += 1;
      s[x + 3][y + 2] += 1;
      s[x + 2][y + 1] += 1;
      s[x + 2][y + 3] += 1;
    } else if (z == 2) {
      for (l = x + 1; l <= x + 3; l++) {
        for (m = y + 1; m <= y + 3; m++) {
          s[l][m] += 1;
        }
      }
    } else if (z == 3) {
      for (l = x + 1; l <= x + 3; l++) {
        for (m = y + 1; m <= y + 3; m++) {
          s[l][m] += 1;
          s[x][y + 2] += 1;
          s[x + 4][y + 2] += 1;
          s[x + 2][y] += 1;
          s[x + 2][y + 4] += 1;
        }
      }
    }
  }
  for (n = 2; n < 12; n++) {
    for (o = 2; o < 12; o++) {
      if (max < s[n][o]) {
        max = s[n][o];
      }
      if (s[n][o] == 0) {
        count += 1;
      }
    }
  }
  cout << count << endl;
  cout << max << endl;
  return 0;
}
Problem p00026 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  int x, y, s;
  char a, b;
  vector<int> X, Y, S, m;
  vector<int> L1 = {-1, 1}, L2 = {-1, 0, 1}, L3 = {-2, 2};
  while (cin >> x >> a >> y >> b >> s) {
    X.push_back(x);
    Y.push_back(y);
    S.push_back(s);
  }
  vector<vector<int>> matrix;
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 30; j++) {
      m.push_back(0);
    }
    matrix.push_back(m);
  }
  for (int i = 0; i < X.size(); i++) {
    if (S[i] == 1) {
      matrix[X[i] + 10][Y[i] + 10] += 1;
      for (int j = 0; j < L1.size(); j++) {
        matrix[X[i] + 10 + L1[j]][Y[i] + 10] += 1;
        matrix[X[i] + 10][Y[i] + 10 + L1[j]] += 1;
      }
    } else if (S[i] == 2) {
      for (int j = 0; j < L2.size(); j++) {
        for (int k = 0; k < L2.size(); k++) {
          matrix[X[i] + 10 + L2[j]][Y[i] + 10 + L2[k]] += 1;
        }
      }
    } else {
      for (int k = 0; k < L2.size(); k++) {
        for (int j = 0; j < L2.size(); j++) {
          matrix[X[i] + 10 + L2[k]][Y[i] + 10 + L2[j]] += 1;
        }
      }
      for (int j = 0; j < L3.size(); j++) {
        matrix[X[i] + 10 + L3[j]][Y[i] + 10] += 1;
        matrix[X[i] + 10][Y[i] + 10 + L3[j]] += 1;
      }
    }
  }
  int ctr1 = 0, max = INT_MIN;
  for (int i = 10; i < 20; i++) {
    for (int j = 10; j < 20; j++) {
      if (matrix[i][j] == 0) {
        ctr1++;
      } else {
        if (max < matrix[i][j])
          max = matrix[i][j];
      }
    }
  }
  cout << ctr1 << endl;
  cout << max << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  int x, y, s;
  vector<int> X, Y, S, m;
  vector<int> L1 = {-1, 1}, L2 = {-1, 0, 1}, L3 = {-2, 2};
  while (scanf("%d,%d,%d", &x, &y, &s)) {
    X.push_back(x);
    Y.push_back(y);
    S.push_back(s);
  }
  vector<vector<int>> matrix;
  for (int i = 0; i < 30; i++) {
    for (int j = 0; i < 30; i++) {
      m.push_back(0);
    }
    matrix.push_back(m);
  }
  for (int i = 0; i < X.size(); i++) {
    if (S[i] == 1) {
      matrix[X[i] + 10][Y[i] + 10] += 1;
      for (int j = 0; j < L1.size(); j++) {
        matrix[X[i] + 10 + L1[j]][Y[i] + 10] += 1;
        matrix[X[i] + 10][Y[i] + 10 + L1[j]] += 1;
      }
    } else if (S[i] == 2) {
      for (int j = 0; j < L2.size(); j++) {
        for (int k = 0; k < L2.size(); k++) {
          matrix[X[i] + 10 + L2[j]][Y[i] + 10 + L2[k]] += 1;
        }
      }
    } else {
      for (int k = 0; k < L2.size(); k++) {
        for (int j = 0; j < L2.size(); i++) {
          matrix[X[i] + 10 + L2[k]][Y[i] + 10 + L2[j]] += 1;
        }
      }
      for (int j = 0; j < L3.size(); j++) {
        matrix[X[i] + 10 + L3[j]][Y[i] + 10] += 1;
        matrix[X[i] + 10][Y[i] + 10 + L3[j]] += 1;
      }
    }
  }
  int ctr1 = 0, max = INT_MAX;
  for (int i = 10; i < 20; i++) {
    for (int j = 10; j < 20; j++) {
      if (matrix[i][j] == 0) {
        ctr1++;
      } else {
        if (max < matrix[i][j])
          max = matrix[i][j];
      }
    }
  }
  cout << ctr1 << endl;
  cout << max << endl;
  return 0;
}
Problem p00026 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
int mem[14][14] = {}, i = 0, X[50], Y[50], S[50], flag = 0, max = 0, x, y, s;
int main() {
  char b;
  while (std::cin >> x >> b >> y >> b >> s) {
    Y[i] = y, S[i] = s, X[i] = x;
    i += 1;
  }
  for (int a = 0; a < i; a += 1) {
    if (S[a] >= 1) {
      mem[X[a] + 2][Y[a] + 2] += 1;
      mem[X[a] + 1][Y[a] + 2] += 1;
      mem[X[a] + 3][Y[a] + 2] += 1;
      mem[X[a] + 2][Y[a] + 1] += 1;
      mem[X[a] + 2][Y[a] + 3] += 1;
    }
    if (S[a] >= 2) {
      mem[X[a] + 1][Y[a] + 1] += 1;
      mem[X[a] + 1][Y[a] + 3] += 1;
      mem[X[a] + 3][Y[a] + 1] += 1;
      mem[X[a] + 3][Y[a] + 3] += 1;
    }
    if (S[a] >= 3) {
      mem[X[a]][Y[a] + 2] += 1;
      mem[X[a] + 4][Y[a] + 2] += 1;
      mem[X[a] + 2][Y[a] + 4] += 1;
      mem[X[a] + 2][Y[a]] += 1;
    }
  }
  for (int i = 0; i < 10; i += 1)
    for (int j = 0; j < 10; j += 1) {
      if (0 == mem[i + 2][j + 2])
        flag += 1;
      if (max < mem[i + 2][j + 2])
        max = mem[i + 2][j + 2];
    }
  std::cout << flag << std::endl;
  std::cout << max << std::endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>
int mem[14][14] = {}, i = 0, X[50], Y[50], S[50], flag = 0, max = 0, x, y, s;
int main() {
  char b;
  while (1) {
    std::cin >> x >> b >> y >> b >> s;
    Y[i] = y, S[i] = s, X[i] = x;
    i += 1;
    for (int a = 0; a < i; a += 1) {
      if (S[a] >= 1) {
        mem[X[a] + 2][Y[a] + 2] += 1;
        mem[X[a] + 1][Y[a] + 2] += 1;
        mem[X[a] + 3][Y[a] + 2] += 1;
        mem[X[a] + 2][Y[a] + 1] += 1;
        mem[X[a] + 2][Y[a] + 3] += 1;
      }
      if (S[a] >= 2) {
        mem[X[a] + 1][Y[a] + 1] += 1;
        mem[X[a] + 1][Y[a] + 3] += 1;
        mem[X[a] + 3][Y[a] + 1] += 1;
        mem[X[a] + 3][Y[a] + 3] += 1;
      }
      if (S[a] >= 3) {
        mem[X[a]][Y[a] + 2] += 1;
        mem[X[a] + 4][Y[a] + 2] += 1;
        mem[X[a] + 2][Y[a] + 4] += 1;
        mem[X[a] + 2][Y[a]] += 1;
      }
    }
    for (int i = 0; i < 10; i += 1)
      for (int j = 0; j < 10; j += 1) {
        if (0 == mem[i + 2][j + 2])
          flag += 1;
        if (max < mem[i + 2][j + 2])
          max = mem[i + 2][j + 2];
      }
    std::cout << flag << std::endl;
    std::cout << max << std::endl;
  }
  return 0;
}
Problem p00026 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int a[10][10] = {}, x, y, size, dumy = 0, max = 0, ans = 0;
  int mx[13] = {0, 0, -1, 1, 0, -1, 1, -1, 1, 0, -2, 2, 0},
      my[13] = {0, -1, 0, 0, 1, -1, -1, 1, 1, -2, 0, 0, 2};
  while (scanf("%d,%d,%d", &x, &y, &size) != EOF) {
    dumy = 4 * size + 1;
    // cout<<size<<endl;
    for (int i = 0; i < dumy; i++) {
      if (x + mx[i] >= 0 && y + my[i] >= 0 && x + mx[i] < 10 && y + my[i] < 10)
        a[x + mx[i]][y + my[i]]++;
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (a[i][j] == 0) {
        ans++;
      } else {
        if (max <= a[i][j])
          max = a[i][j];
      }
    }
  }
  cout << ans << endl << max << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int a[10][10] = {}, x, y, size, dumy = 0, max = 0, ans = 0;
  int mx[12] = {0, -1, 1, 0, -1, 1, -1, 1, 0, -2, 2, 0},
      my[12] = {-1, 0, 0, 1, -1, -1, 1, 1, -2, 0, 0, 2};
  while (scanf("%d,%d,%d", &x, &y, &size) != EOF) {
    dumy = 4 * size;
    // cout<<size<<endl;
    for (int i = 0; i < dumy; i++) {
      if (x + mx[i] >= 0 && y + my[i] >= 0)
        a[x + mx[i]][y + my[i]]++;
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (a[i][j] == 0) {
        ans++;
      } else {
        if (max <= a[i][j])
          max = a[i][j];
      }
    }
  }
  cout << ans << endl << max << endl;
  return 0;
}
Problem p00026 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

const int SMALL = 1;
const int MIDDLE = 2;
const int LARGE = 3;
int paper[10][10] = {0};

void Dropping_Ink(int x, int y, int size) {
  paper[y][x]++;
  if (x - 1 > -1)
    paper[y][x - 1]++;
  if (x + 1 < 10)
    paper[y][x + 1]++;
  if (y - 1 > -1)
    paper[y - 1][x]++;
  if (y + 1 < 10)
    paper[y + 1][x]++;

  if (size >= MIDDLE) {
    if (x - 1 > -1) {
      if (y - 1 > -1)
        paper[y - 1][x - 1]++;
      if (y + 1 < 10)
        paper[y + 1][x - 1]++;
    }
    if (x + 1 < 10) {
      if (y - 1 > -1)
        paper[y - 1][x + 1]++;
      if (y + 1 < 10)
        paper[y + 1][x + 1]++;
    }
  }

  if (size == LARGE) {
    if (x - 2 > -1)
      paper[y][x - 2]++;
    if (x + 2 < 10)
      paper[y][x + 2]++;
    if (y - 2 > -1)
      paper[y - 2][x]++;
    if (y + 2 < 10)
      paper[y + 2][x]++;
  }
}

int main() {
  int x, y, size, white, color;
  char c[2];

  while (cin >> x >> c[0] >> y >> c[1] >> size) {
    if (cin.eof())
      break;

    Dropping_Ink(x, y, size);
  }

  white = 0;
  color = 0;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (paper[i][j] == 0)
        white++;
      if (paper[i][j] > color)
        color = paper[i][j];
    }
  }

  cout << white << endl << color << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int SMALL = 1;
int MIDDLE = 2;
int BIG = 3;
int paper[10][10] = {0};

void Dropping_Ink(int x, int y, int size) {
  if (x - 1 > -1)
    paper[y][x - 1]++;
  if (x + 1 < 10)
    paper[y][x + 1]++;
  if (y - 1 > -1)
    paper[y - 1][x]++;
  if (y + 1 < 10)
    paper[y + 1][x]++;

  if (size >= MIDDLE) {
    if (x - 1 > -1) {
      if (y - 1 > -1)
        paper[y - 1][x - 1]++;
      if (y + 1 < 10)
        paper[y + 1][x - 1]++;
    }
    if (x + 1 < 10) {
      if (y - 1 > -1)
        paper[y - 1][x + 1]++;
      if (y + 1 < 10)
        paper[y + 1][x + 1]++;
    }
  }

  if (size >= BIG) {
    if (x - 2 > -1)
      paper[y - 2][x]++;
    if (x + 2 < 10)
      paper[y + 2][x]++;
    if (y - 2 > -1)
      paper[y][x - 2]++;
    if (y + 2 < 10)
      paper[y][x + 2]++;
  }
}

int main() {
  int x, y, size, white, color;
  char c[2];

  while (cin >> x >> c[0] >> y >> c[1] >> size) {
    if (cin.eof())
      break;

    Dropping_Ink(x, y, size);

    white = 0;
    color = 0;

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (paper[i][j] == 0)
          white++;
        if (paper[i][j] > color)
          color = paper[i][j];
      }
    }
  }

  cout << white << endl << color << endl;

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

#include <cstring>
#include <iostream>

using namespace std;

int small_x[4] = {-1, 0, 0, 1};
int small_y[4] = {0, -1, 1, 0};

int medium_x[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int medium_y[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int large_x[12] = {-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2};
int large_y[12] = {0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0};

void solve() {
  int Field[14][14];
  memset(Field, 0, sizeof(Field));
  int a, b, c;
  while (~scanf("%d,%d,%d", &a, &b, &c)) {
    ++Field[b + 2][a + 2];
    if (c == 1) {
      for (int i = 0; i < 4; ++i) {
        ++Field[b + 2 + small_y[i]][a + 2 + small_x[i]];
      }
    } else if (c == 2) {
      for (int i = 0; i < 8; ++i) {
        ++Field[b + 2 + medium_y[i]][a + 2 + medium_x[i]];
      }
    } else if (c == 3) {
      for (int i = 0; i < 12; ++i) {
        ++Field[b + 2 + large_y[i]][a + 2 + large_x[i]];
      }
    }
  }
  int count = 0;
  int Max = 0;
  for (int i = 2; i < 12; ++i) {
    for (int j = 2; j < 12; ++j) {
      if (Field[i][j] == 0) {
        ++count;
      }
      if (Max < Field[i][j]) {
        Max = Field[i][j];
      }
    }
  }
  cout << count << endl;
  cout << Max << endl;
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int small_x[4] = {-1, 0, 0, 1};
int small_y[4] = {0, -1, 1, 0};

int medium_x[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int medium_y[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int large_x[12] = {-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2};
int large_y[12] = {0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0};

void solve() {
  int Field[14][14];
  memset(Field, 0, sizeof(Field));
  int a, b, c;
  while (scanf("%d,%d,%d", &a, &b, &c)) {
    ++Field[b + 2][a + 2];
    if (c == 1) {
      for (int i = 0; i < 4; ++i) {
        ++Field[b + 2 + small_y[i]][a + 2 + small_x[i]];
      }
    } else if (c == 2) {
      for (int i = 0; i < 8; ++i) {
        ++Field[b + 2 + medium_y[i]][a + 2 + medium_x[i]];
      }
    } else if (c == 3) {
      for (int i = 0; i < 12; ++i) {
        ++Field[b + 2 + large_y[i]][a + 2 + large_x[i]];
      }
    }
  }
  int count = 0;
  int Max = 0;
  for (int i = 2; i < 12; ++i) {
    for (int j = 2; j < 12; ++j) {
      if (Field[i][j] == 0) {
        ++count;
      }
      if (Max < Field[i][j]) {
        Max = Field[i][j];
      }
    }
  }
  cout << count << endl;
  cout << Max << endl;
}

int main() {
  solve();
  return (0);
}
Problem p00026 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int dc[3] = {5, 9, 13};
int dx[3][13] = {{0, 0, 0, -1, 1},
                 {-1, -1, -1, 0, 0, 0, 1, 1, 1},
                 {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}};
int dy[3][13] = {{0, 1, -1, 0, 0},
                 {-1, 0, 1, -1, 0, 1, -1, 0, 1},
                 {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}};

int main() {
  int a, b, c;
  int d[10][10] = {0};
  while (~scanf("%d,%d,%d", &a, &b, &c)) {
    c--;
    rep(i, dc[c]) {
      int tx = a + dx[c][i], ty = b + dy[c][i];
      if (tx < 0 || ty < 0 || ty > 9 || tx > 9)
        continue;
      d[ty][tx]++;
    }
  }
  int white = 0;
  int ans = 0;
  rep(i, 10) rep(j, 10) {
    if (d[i][j] == 0)
      white++;
    else
      ans = max(d[i][j], ans);
  }
  cout << white << endl << ans << endl;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int dc[3] = {4, 10, 13};
int dx[3][13] = {{-1, 0, -1, 0, 0},
                 {-1, -1, -1, 0, 0, 0, 1, 1, 1},
                 {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}};
int dy[3][13] = {{0, 0, 0, -1, 1},
                 {-1, 0, 1, -1, 0, 1, -1, 0, 1},
                 {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}};

int main() {
  int a, b, c;
  int d[10][10] = {0};
  while (scanf("%d,%d,%d", &a, &b, &c)) {
    rep(i, dc[c]) {
      int tx = a + dx[c][i], ty = b + dy[c][i];
      if (tx < 0 || ty < 0 || ty > 9 || tx > 9)
        continue;
      d[ty][tx]++;
    }
  }
  int white = 0;
  int ans = 0;
  rep(i, 10) rep(j, 10) {
    if (d[i][j] == 0)
      white++;
    else
      ans = max(d[i][j], ans);
  }
  cout << white << endl << ans << endl;
}
Problem p00026 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int G[101][101];

bool inF(int x, int y) { return 0 <= x < 10 && 0 <= y < 10; }

void draw(int x, int y) {
  if (inF(x, y)) {
    G[y][x]++;
  }
}

int main() {
  int a, b, c;
  char d;

  fill(G[0], G[10], 0);

  while (cin >> a >> d >> b >> d >> c) {
    draw(a, b);
    switch (c) {
    case 3:
      draw(a - 2, b);
      draw(a + 2, b);
      draw(a, b - 2);
      draw(a, b + 2);
    case 2:
      draw(a - 1, b - 1);
      draw(a + 1, b - 1);
      draw(a - 1, b + 1);
      draw(a + 1, b + 1);
    case 1:
      draw(a - 1, b);
      draw(a + 1, b);
      draw(a, b - 1);
      draw(a, b + 1);
      break;
    }
  }

  int clrNum = 0, mx = 0;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      mx = max(mx, G[i][j]);
      if (G[i][j] == 0)
        clrNum++;
    }
  }

  cout << clrNum << endl << mx << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int G[10][10];

bool inF(int x, int y) { return 0 <= x < 10 && 0 <= y < 10; }

void draw(int x, int y) {
  if (inF(x, y)) {
    G[y][x]++;
  }
}

int main() {
  int a, b, c;
  char d;

  fill(G[0], G[9] + 10, 0);

  while (cin >> a >> d >> b >> d >> c) {
    draw(a, b);
    switch (c) {
    case 3:
      draw(a - 2, b);
      draw(a + 2, b);
      draw(a, b - 2);
      draw(a, b + 2);
    case 2:
      draw(a - 1, b - 1);
      draw(a + 1, b - 1);
      draw(a - 1, b + 1);
      draw(a + 1, b + 1);
    case 1:
      draw(a - 1, b);
      draw(a + 1, b);
      draw(a, b - 1);
      draw(a, b + 1);
      break;
    }
  }

  int clrNum = 0, mx = 0;

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      mx = max(mx, G[i][j]);
      if (G[i][j] == 0)
        clrNum++;
    }
  }

  cout << clrNum << endl << mx << endl;

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

#include <iostream>
#include <stdio.h>
using namespace std;
int m[10][10];
void small(int x, int y, int r) {
  if (y - r >= 0)
    m[x][y - r]++;
  if (x - r >= 0)
    m[x - r][y]++;
  if (x + r <= 9)
    m[x + r][y]++;
  if (y + r <= 9)
    m[x][y + r]++;
  m[x][y]++;
}
void middle(int x, int y) {
  for (int i = -1; i < 2; i++)
    for (int j = -1; j < 2; j++)
      if (x + i >= 0 && x + i <= 9 && y + j >= 0 && y + j <= 9)
        m[x + i][y + j]++;
}
void large(int x, int y) {
  middle(x, y);
  small(x, y, 2);
  m[x][y]--;
}

int main() {
  int x, y, n, i, j, h, k;
  while (scanf("%d,%d,%d", &x, &y, &n) != EOF) {
    if (n == 1)
      small(x, y, 1);
    if (n == 2)
      middle(x, y);
    if (n == 3)
      large(x, y);
  }
  n = 0;
  h = 0;
  k = 0;
  for (i = 0; i < 10; i++)
    for (j = 0; j < 10; j++) {
      if (m[i][j] == 0)
        k++;
      else
        h = h < m[i][j] ? m[i][j] : h;
    }
  cout << k << endl << h << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int m[10][10];
void small(int x, int y, int r) {
  if (y - r >= 0)
    m[x][y - r]++;
  if (x - r >= 0)
    m[x - r][y]++;
  if (x + r <= 9)
    m[x + r][y]++;
  if (y + r <= 9)
    m[x][y + r]++;
  m[x][y]++;
}
void middle(int x, int y) {
  for (int i = -1; i < 2; i++)
    for (int j = -1; j < 2; j++)
      if (x + i >= 0 && x + i <= 9 && y + j >= 0 && y + j <= 9)
        m[x + i][y + j]++;
}
void large(int x, int y) {
  middle(x, y);
  small(x, y, 2);
  m[x][y]--;
}

int main() {
  int x, y, n, i, j, h, k;
  while (scanf("%d,%d,%d", &x, &y, &n)) {
    if (n == 1)
      small(x, y, 1);
    if (n == 2)
      middle(x, y);
    if (n == 3)
      large(x, y);
  }
  n = 0;
  h = 0;
  k = 0;
  for (i = 0; i < 10; i++)
    for (j = 0; j < 10; j++) {
      if (m[i][j] == 0)
        k++;
      else
        h = h < m[i][j] ? m[i][j] : h;
    }
  cout << k << endl << h << endl;
  return 0;
}