Problem p00026 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <complex>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define li long long int
#define rep(i, to) for (int i = 0; i < ((int)(to)); i++)
#define repp(i, start, to) for (int i = (int)(start); i < ((int)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define F first
#define S second
#define p2(a, b) cout << a << "\\t" << b << endl
#define p3(a, b, c) cout << a << "\\t" << b << "\\t" << c << endl

int main() {
  li dx[13] = {0, -1, 1, 0, 0, 1, 1, -1, -1, 2, -2, 0, 0};
  li dy[13] = {0, 0, 0, -1, 1, 1, -1, 1, -1, 0, 0, 2, -2};
  li lim[3] = {5, 9, 13};

  li kami[10][10];
  rep(i, 10) rep(j, 10) kami[i][j] = 0;

  int x, y, s;
  while (~scanf("%d,%d,%d", &x, &y, &s)) {
    rep(i, lim[s - 1]) {
      li nx = x + dx[i];
      li ny = y + dy[i];
      if (min(nx, ny) >= 0 && max(nx, ny) < 10)
        kami[nx][ny]++;
    }
  }

  li siro = 0;
  li ma = 0;

  rep(i, 10) {
    rep(j, 10) {
      ma = max(ma, kami[i][j]);
      if (kami[i][j] == 0)
        siro++;
    }
  }
  cout << siro << endl << ma << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <complex>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define li long long int
#define rep(i, to) for (int i = 0; i < ((int)(to)); i++)
#define repp(i, start, to) for (int i = (int)(start); i < ((int)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define F first
#define S second
#define p2(a, b) cout << a << "\\t" << b << endl
#define p3(a, b, c) cout << a << "\\t" << b << "\\t" << c << endl

int main() {
  li dx[13] = {0, -1, 1, 0, 0, 1, 1, -1, -1, 2, -2, 0, 0};
  li dy[13] = {0, 0, 0, -1, 1, 1, -1, 1, -1, 0, 0, 2, -2};
  li lim[3] = {5, 9, 13};

  li kami[10][10];
  rep(i, 10) rep(j, 10) kami[i][j] = 0;

  int x, y, s;
  while (scanf("%d,%d,%d", &x, &y, &s)) {
    rep(i, lim[s - 1]) {
      li nx = x + dx[i];
      li ny = y + dy[i];
      if (min(nx, ny) >= 0 && max(nx, ny) < 10)
        kami[nx][ny]++;
    }
  }

  li siro = 0;
  li ma = 0;

  rep(i, 10) {
    rep(j, 10) {
      ma = max(ma, kami[i][j]);
      if (kami[i][j] == 0)
        siro++;
    }
  }
  cout << siro << endl << ma << endl;

  return 0;
}