Problem p03637 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

// bool operator< (pint a, pint b) {
// return a.second < b.second;

//}

ll gcd(ll a, ll b) {

  if (b == 0)
    return a;

  return gcd(b, a % b);
}

ll max(ll a, ll b) {
  if (a < b) {
    return b;
  } else
    return a;
}

ll min(ll a, ll b) {
  if (a < b)
    return a;

  return b;
}

pint dx[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

vector<pint> list;

void floyd(int N, ll **d) {

  rep(k, N + 1) {
    rep(i, N + 1) {
      if (d[i + 1][k + 1] == inf)
        continue;
      rep(j, N + 1) {
        if (d[j + 1][k + 1] == inf)
          continue;

        d[i + 1][j + 1] =
            min(d[i + 1][j + 1], d[i + 1][k + 1] + d[j + 1][k + 1]);
      }
    }
  }
}

ll vis[100005];
ll d[100005];
vector<pint> M[100005];
vector<ll> anslist;
void dfs(ll K, ll dist) {

  d[K] = dist;
  vis[K] = 1;
  for (int i = 0; i < M[K].size(); i++) {
    if (vis[M[K][i].first] == 0) {
      dfs(M[K][i].first, dist + M[K][i].second);
    }
  }
}

ll a[10005];

int main() {
  ll N, num_kisuu = 0, num_four = 0;

  cin >> N;

  rep(i, N) {
    cin >> a[i];

    num_kisuu += (a[i] % 2 == 1) ? 1 : 0;
    num_four += (a[i] % 4 == 0) ? 1 : 0;
  }
  ll num_guusuu = N - num_kisuu;

  if (num_four >= num_kisuu)
    cout << "Yes" << endl;

  else if (num_four == num_kisuu - 1 && num_guusuu - num_four == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

// bool operator< (pint a, pint b) {
// return a.second < b.second;

//}

ll gcd(ll a, ll b) {

  if (b == 0)
    return a;

  return gcd(b, a % b);
}

ll max(ll a, ll b) {
  if (a < b) {
    return b;
  } else
    return a;
}

ll min(ll a, ll b) {
  if (a < b)
    return a;

  return b;
}

pint dx[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

vector<pint> list;

void floyd(int N, ll **d) {

  rep(k, N + 1) {
    rep(i, N + 1) {
      if (d[i + 1][k + 1] == inf)
        continue;
      rep(j, N + 1) {
        if (d[j + 1][k + 1] == inf)
          continue;

        d[i + 1][j + 1] =
            min(d[i + 1][j + 1], d[i + 1][k + 1] + d[j + 1][k + 1]);
      }
    }
  }
}

ll vis[100005];
ll d[100005];
vector<pint> M[100005];
vector<ll> anslist;
void dfs(ll K, ll dist) {

  d[K] = dist;
  vis[K] = 1;
  for (int i = 0; i < M[K].size(); i++) {
    if (vis[M[K][i].first] == 0) {
      dfs(M[K][i].first, dist + M[K][i].second);
    }
  }
}

ll a[100005];

int main() {
  ll N, num_kisuu = 0, num_four = 0;

  cin >> N;

  rep(i, N) {
    cin >> a[i];

    num_kisuu += (a[i] % 2 == 1) ? 1 : 0;
    num_four += (a[i] % 4 == 0) ? 1 : 0;
  }
  ll num_guusuu = N - num_kisuu;

  if (num_four >= num_kisuu)
    cout << "Yes" << endl;

  else if (num_four == num_kisuu - 1 && num_guusuu - num_four == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}