Problem p02841 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <array>
#include <bitset>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

char alfa[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
               'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

inline void finish() {
  cout << -1 << endl;
  exit(0);
}

unsigned GetDigit(unsigned num) { return log10(num) + 1; }

template <typename T> inline void debug(vector<T> v) {
  cout << "[";
  for (ll i = 0; i < v.size() - 1; ++i) {
    cout << v[i] << ", ";
  }
  cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
  while (true) {
    Main();
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  bool debug = true;
  if (debug) {
    cout << "\x1b[41m"
         << "Debug Mode " << endl;
  }
  (debug) ? DebugMain() : Main();
  return 0;
}

ll calcC(ld lastNum, ld calcNum, ll A, ll B, ll X) {
  if (calcNum < 1) {
    return 0;
  }

  ll ans;

  ans = A * calcNum + B * GetDigit(calcNum);

  if (calcNum == lastNum) {
    return calcNum;
  }

  if (ans > X) {
    return calcC(calcNum, calcNum - (fabs(calcNum - lastNum) / 2), A, B, X);
  } else {
    return calcC(calcNum, calcNum + (fabs(calcNum - lastNum) / 2), A, B, X);
  }
}

inline void Main() {
  ll X, Y, N;
  ll A, B;
  ll M1, D1, M2, D2;
  ld ans;
  string S;

  cin >> M1 >> D1 >> M2 >> D2;

  if (M1 != M2) {
    cout << 1;
  } else {
    cout << 0;
  }
}


Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

char alfa[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
               'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

inline void finish() {
  cout << -1 << endl;
  exit(0);
}

unsigned GetDigit(unsigned num) { return log10(num) + 1; }

template <typename T> inline void debug(vector<T> v) {
  cout << "[";
  for (ll i = 0; i < v.size() - 1; ++i) {
    cout << v[i] << ", ";
  }
  cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
  while (true) {
    Main();
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  bool debug = false;
  if (debug) {
    cout << "\x1b[41m"
         << "Debug Mode " << endl;
  }
  (debug) ? DebugMain() : Main();
  return 0;
}

ll calcC(ld lastNum, ld calcNum, ll A, ll B, ll X) {
  if (calcNum < 1) {
    return 0;
  }

  ll ans;

  ans = A * calcNum + B * GetDigit(calcNum);

  if (calcNum == lastNum) {
    return calcNum;
  }

  if (ans > X) {
    return calcC(calcNum, calcNum - (fabs(calcNum - lastNum) / 2), A, B, X);
  } else {
    return calcC(calcNum, calcNum + (fabs(calcNum - lastNum) / 2), A, B, X);
  }
}

inline void Main() {
  ll X, Y, N;
  ll A, B;
  ll M1, D1, M2, D2;
  ld ans;
  string S;

  cin >> M1 >> D1 >> M2 >> D2;

  if (M1 != M2) {
    cout << 1;
  } else {
    cout << 0;
  }
}