Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

#define rep(i, x) for (Int i = 0; i < (Int)(x); i++)
#define rrep(i, x) for (Int i = ((Int)(x)-1); i >= 0; i--)
#define _upgrade                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define pb push_back

template <class T1, class T2> void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <class T1, class T2> void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1, 0, -1, 0};
Int dy[4] = {0, 1, 0, -1};
// const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;

// ****************************************CODE***************************************//

int dfs(int a, int b, int c) {
  if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
    return 0;
  }

  return dfs((b + c) / 2, (a + c) / 2, (a + b) / 2) + 1;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = dfs(a, b, c);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

#define rep(i, x) for (Int i = 0; i < (Int)(x); i++)
#define rrep(i, x) for (Int i = ((Int)(x)-1); i >= 0; i--)
#define _upgrade                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define pb push_back

template <class T1, class T2> void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <class T1, class T2> void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1, 0, -1, 0};
Int dy[4] = {0, 1, 0, -1};
// const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;

// ****************************************CODE***************************************//

int dfs(int a, int b, int c) {
  if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
    return 0;
  }

  if (a == b && b == c)
    return -1;

  return dfs((b + c) / 2, (a + c) / 2, (a + b) / 2) + 1;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = dfs(a, b, c);
  cout << ans << endl;
  return 0;
}