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

#include <stdio.h>

int main() {
  int m, n, i, j, k;
  long int K;
  int a, b, c, d;
  char tmp;
  int J[1002][1002] = {0}, O[1002][1002] = {0}; // I[1002][1002]={0};
  int tmp1, tmp2, tmp3;

  scanf("%d %d\\n%ld\\n", &m, &n, &K);
  // for(i=0;i<m;i++){
  //       gets(map[i]);
  // printf("%s\\n",&map[i]);
  //}
  // printf("%c\\n",map[0][3]);
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%c", &tmp);
      if (tmp == '\\n')
        scanf("%c", &tmp);
      if (i == 1 && j == 1) {

      } else if (i == 1) {
        J[i][j] = J[i][j - 1];
        O[i][j] = O[i][j - 1];
        // I[i][j]=I[i][j-1];
      } else if (j == 1) {
        J[i][j] = J[i - 1][j];
        O[i][j] = O[i - 1][1];
        // I[i][j]=I[i-1][1];
      } else {
        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
        // I[i][j]=I[i-1][j]+I[i][j-1]-I[i-1][j-1];
      }
      if (tmp == 'J') {
        // printf("j\\n");
        J[i][j] += 1;
        // printf("%d:%d J%d\\n",i,j,J[i][j]);
      } else if (tmp == 'O') {
        O[i][j] += 1;
        // printf("%d:%d O%d\\n",i,j,O[i][j]);
      } else if (tmp == 'I') {
        // I[i][j]+=1;
        // printf("%d:%d I%d\\n",i,j,I[i][j]);
      }
    }
  }
  scanf("%c", &tmp);
  for (i = 0; i < K; i++) {
    scanf("%d %d %d %d\\n", &a, &b, &c, &d);
    tmp1 = J[c][d] - J[c][b - 1] - J[a - 1][d] + J[a - 1][b - 1];
    printf("%d ", tmp1);
    tmp2 = O[c][d] - O[c][b - 1] - O[a - 1][d] + O[a - 1][b - 1];
    printf("%d ", tmp2);
    tmp3 = (c - a + 1) * (d - b + 1) - tmp1 - tmp2;
    printf("%d\\n", tmp3);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int m, n, i, j, k;
  long int K;
  int a, b, c, d;
  char tmp;
  int I[124][1024] = {0}, O[124][1024] = {0}, J[124][1024] = {0};
  int tmp1;

  scanf("%d %d\\n%ld\\n", &m, &n, &K);
  // for(i=0;i<m;i++){
  //	gets(map[i]);
  // printf("%s\\n",&map[i]);
  //}
  // printf("%c\\n",map[0][3]);
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%c", &tmp);
      if (tmp == '\\n')
        scanf("%c", &tmp);
      if (i == 1 && j == 1) {

      } else if (i == 1) {
        J[i][j] = J[i][j - 1];
        O[i][j] = O[i][j - 1];
        I[i][j] = I[i][j - 1];
      } else if (j == 1) {
        J[i][j] = J[i - 1][j];
        O[i][j] = O[i - 1][1];
        I[i][j] = I[i - 1][1];
      } else {
        J[i][j] = J[i - 1][j] + J[i][j - 1] - J[i - 1][j - 1];
        O[i][j] = O[i - 1][j] + O[i][j - 1] - O[i - 1][j - 1];
        I[i][j] = I[i - 1][j] + I[i][j - 1] - I[i - 1][j - 1];
      }
      if (tmp == 'J') {
        // printf("j\\n");
        J[i][j] += 1;
        // printf("%d:%d J%d\\n",i,j,J[i][j]);
      } else if (tmp == 'O') {
        O[i][j] += 1;
        // printf("%d:%d O%d\\n",i,j,O[i][j]);
      } else if (tmp == 'I') {
        I[i][j] += 1;
        // printf("%d:%d I%d\\n",i,j,I[i][j]);
      }
    }
  }
  scanf("%c", &tmp); //\\nを取る
  for (i = 0; i < K; i++) {
    scanf("%d %d %d %d\\n", &a, &b, &c, &d);
    tmp1 = J[c][d] - J[c][b - 1] - J[a - 1][d] + J[a - 1][b - 1];
    printf("%d ", tmp1);
    tmp1 = O[c][d] - O[c][b - 1] - O[a - 1][d] + O[a - 1][b - 1];
    printf("%d ", tmp1);
    tmp1 = I[c][d] - I[c][b - 1] - I[a - 1][d] + I[a - 1][b - 1];
    printf("%d\\n", tmp1);
  }
  return 0;
}