Problem p03435 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a, b) memset((a), (b), sizeof(a))
#define mod(x) ((x) % MOD)
#define pii pair<int, int>
#define wz cout << "-----" << endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
const int Move_[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1};

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

void init() {}

int a[4][4];
vector<int> aa;
int main() {
  //    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
  //    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
  //    ios_base::sync_with_stdio(0);
  init();
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i <= 100; i++)
    aa.push_back(i);
  //	sort(aa.begin(),aa.end());
  //	int len = unique(aa.begin(),aa.end()) - aa.begin();
  for (int a1 = 0; a1 < 101; a1++) {
    for (int a2 = 0; a2 < 101; a2++) {
      for (int a3 = 0; a3 < 101; a3++) {
        for (int b1 = 0; b1 < 101; b1++) {
          for (int b2 = 0; b2 < 101; b2++) {
            for (int b3 = 0; b3 < 101; b3++) {
              bool flg = false;
              if (a[1][1] != aa[a1] + aa[b1])
                flg = true;
              if (a[1][2] != aa[a1] + aa[b2])
                flg = true;
              if (a[1][3] != aa[a1] + aa[b3])
                flg = true;
              if (a[2][1] != aa[a2] + aa[b1])
                flg = true;
              if (a[2][2] != aa[a2] + aa[b2])
                flg = true;
              if (a[2][3] != aa[a2] + aa[b3])
                flg = true;
              if (a[3][1] != aa[a3] + aa[b1])
                flg = true;
              if (a[3][2] != aa[a3] + aa[b2])
                flg = true;
              if (a[3][3] != aa[a3] + aa[b3])
                flg = true;
              if (!flg) {
                cout << "Yes" << endl;
                return 0;
              }
            }
          }
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a, b) memset((a), (b), sizeof(a))
#define mod(x) ((x) % MOD)
#define pii pair<int, int>
#define wz cout << "-----" << endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
const int Move_[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1};

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

void init() {}

int a[4][4];
vector<int> aa;
int main() {
  //    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
  //    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
  //    ios_base::sync_with_stdio(0);
  init();
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      cin >> a[i][j];
    }
  }
  for (int k = -1000; k <= 1000; k++) {
    int a2, a3, b1, b2, b3;
    int a1 = k;
    b1 = a[1][1] - k;
    b2 = a[1][2] - k;
    b3 = a[1][3] - k;
    a2 = a[2][1] - b1;
    a3 = a[3][1] - b1;
    bool flg = false;
    if (a[2][2] != a2 + b2)
      flg = true;
    if (a[2][3] != a2 + b3)
      flg = true;
    if (a[3][2] != a3 + b2)
      flg = true;
    if (a[3][3] != a3 + b3)
      flg = true;
    if (!flg) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}