Problem p02843 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define loop(i, a, b) for (lli i = a; i < b; i++)
#define loopb(i, a, b) for (lli i = a; i >= b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// use to avoid collision
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
// for pair in unordered_map
struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
lli power(lli x, lli y) {
  lli res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
bool flag(lli x, lli temp) {
  if (x == 0 && temp >= 0)
    return true;
  else if (x < 0 || temp < 0)
    return false;
  temp--;
  bool a = flag(x - 1, temp);
  bool b = flag(x - 2, temp);
  bool c = flag(x - 3, temp);
  bool d = flag(x - 4, temp);
  bool e = flag(x - 5, temp);
  if (a || b || c || d || e)
    return true;
  else
    return false;
}
lli solve() {
  lli x;
  cin >> x;
  if (x < 100) {
    cout << 0 << "\n";
    return 0;
  }
  lli temp = x / 100;
  x = x % 100;
  if (x == 0) {
    cout << 1 << "\n";
    return 0;
  }
  bool check = flag(x, temp);
  cout << check << "\n";
  return 0;
}
int main() {
  fastio;
  lli t;
  //	cin>>t;
  t = 1;
  while (t > 0) {
    t--;
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define loop(i, a, b) for (lli i = a; i < b; i++)
#define loopb(i, a, b) for (lli i = a; i >= b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
// use to avoid collision
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
// for pair in unordered_map
struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
lli power(lli x, lli y) {
  lli res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
bool flag(lli x, lli temp) {
  if (x == 0 && temp >= 0)
    return true;
  else if (x < 0 || temp < 0)
    return false;
  temp--;
  bool a = flag(x - 1, temp);
  bool b = flag(x - 2, temp);
  bool c = flag(x - 3, temp);
  bool d = flag(x - 4, temp);
  bool e = flag(x - 5, temp);
  if (a || b || c || d || e)
    return true;
  else
    return false;
}
lli solve() {
  lli x;
  cin >> x;
  if (x < 100) {
    cout << 0 << "\n";
    return 0;
  }
  lli temp = x / 100;
  x = x % 100;
  if (x == 0) {
    cout << 1 << "\n";
    return 0;
  }
  if (temp * 5 < x)
    cout << 0 << "\n";
  else
    cout << 1 << "\n";
  //	bool check = flag(x, temp);
  //	cout<<check<<"\n";
  return 0;
}
int main() {
  fastio;
  lli t;
  //	cin>>t;
  t = 1;
  while (t > 0) {
    t--;
    solve();
  }
}