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

#include <bits/stdc++.h>
using namespace std;
int c, n;
int con = 0;
bool coa[1001][1001];
bool cc[101];
bool coacheck() {
  if (con == 0)
    return true;
  else
    return false;
}
int main() {
  cin >> c >> n;
  for (int i = 1; i <= n; i++) {
    string coaster;
    cin >> coaster;
    for (int j = 1; j <= n; j++) {
      int kari = coaster[j - 1] - 48;
      coa[i][j] = kari;
    }
  }

  for (int i = 1; i <= n / 2; i++) {
    for (int j = 1; j <= n / 2; j++) {
      if ((coa[i][j] == coa[i][n - j + 1]) &&
          (coa[i][j] == coa[n - i + 1][j]) &&
          (coa[i][j] == coa[n - i + 1][n - j + 1])) {
      } else {
        con++;
      }
    }
  }

  int coacon = 0;
  if (coacheck())
    coacon++;
  for (int i = 1; i < c; i++) {
    int numcon = 0;
    int num;
    cin >> num;
    int a[202];
    for (int j = 1; j <= num * 2; j++) {
      cin >> a[j];
    }
    for (int j = 1; j <= num; j++) {
      bool check1;
      if ((coa[a[j * 2 - 1]][a[j * 2]] ==
           coa[a[j * 2 - 1]][n + 1 - a[j * 2]]) &&
          (coa[a[j * 2 - 1]][a[j * 2]] ==
           coa[n - a[j * 2 - 1] + 1][a[j * 2]]) &&
          (coa[a[j * 2 - 1]][a[j * 2]] ==
           coa[n - a[j * 2 - 1] + 1][n - a[j * 2] + 1])) {
        check1 = true;
      } else {
        check1 = false;
      }
      if (coa[a[j * 2 - 1]][a[j * 2]] == true)
        coa[a[j * 2 - 1]][a[j * 2]] = false;
      else
        coa[a[j * 2 - 1]][a[j * 2]] = true;
      bool check2;
      if ((coa[a[j * 2 - 1]][a[j * 2]] ==
           coa[a[j * 2 - 1]][n + 1 - a[j * 2]]) &&
          (coa[a[j * 2 - 1]][a[j * 2]] ==
           coa[n - a[j * 2 - 1] + 1][a[j * 2]]) &&
          (coa[a[j * 2 - 1]][a[j * 2]] ==
           coa[n - a[j * 2 - 1] + 1][n - a[j * 2] + 1])) {
        check2 = true;
      } else {
        check2 = false;
      }
      if ((check1 == true) && (check2 == false))
        con++;
      else if ((check1 == false) && (check2 == true))
        con--;
    }
    if (coacheck())
      coacon++;
  }
  cout << coacon << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int c, n;
bool coa[1001][1001];
bool coacheck() {

  for (int i = 1; i <= n / 2; i++) {
    for (int j = 1; j <= n / 2; j++) {
      if ((coa[i][j] == coa[i][n - j + 1]) &&
          (coa[i][j] == coa[n - i + 1][j]) &&
          (coa[i][j] == coa[n - i + 1][n - j + 1])) {
      } else {
        return false;
      }
    }
  }
  return true;
}
int main() {
  cin >> c >> n;
  for (int i = 1; i <= n; i++) {
    string coaster;
    cin >> coaster;
    for (int j = 1; j <= n; j++) {
      int kari = coaster[j - 1] - 48;
      coa[i][j] = kari;
    }
  }
  int coacount = 0;
  if (coacheck())
    coacount++;
  for (int i = 1; i < c; i++) {
    int num;
    cin >> num;
    int a[num * 2];
    for (int j = 0; j < num * 2; j++) {
      cin >> a[j];
    }
    for (int j = 0; j < num; j++) {
      if (coa[a[j * 2]][a[j * 2 + 1]] == true)
        coa[a[j * 2]][a[j * 2 + 1]] = false;
      else
        coa[a[j * 2]][a[j * 2 + 1]] = true;
    }
    if (coacheck())
      coacount++;
  }
  cout << coacount << endl;

  return 0;
}