Problem p03525 (C++)

Buggy submission (status: Runtime Error):
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-28 16:19:15
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
  int flag = 0;
  for (auto e : vec)
    os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &st) {
  int flag = 0;
  for (auto e : st)
    os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &mp) {
  int flag = 0;
  for (auto e : mp)
    os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
  for (T &e : vec)
    is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0)
    std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> d(n);
  cin >> d;

  if (any_of(all(d), [](int e) { return e == 0; })) {
    cout << 0 << endl;
    return 0;
  }

  if (n > 23) {
    cout << 0 << endl;
    return 0;
  }

  map<int, int> mp;

  for (int e : d)
    ++mp[e];

  if (any_of(mp.begin(), mp.end(), [](auto e) { return e.second >= 3; })) {
    cout << 0 << endl;
    return 0;
  }

  abort();

  return 0;
}


Fixed submission:
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-28 16:19:15
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
  int flag = 0;
  for (auto e : vec)
    os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &st) {
  int flag = 0;
  for (auto e : st)
    os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &mp) {
  int flag = 0;
  for (auto e : mp)
    os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
  for (T &e : vec)
    is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0)
    std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> d(n);
  cin >> d;

  if (any_of(all(d), [](int e) { return e == 0; })) {
    cout << 0 << endl;
    return 0;
  }

  if (n > 23) {
    cout << 0 << endl;
    return 0;
  }

  map<int, int> mp;

  for (int e : d)
    ++mp[e];

  if (any_of(mp.begin(), mp.end(), [](auto e) { return e.second >= 3; })) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> t;
  t.emplace_back(0);

  int flag = 1;

  for (auto e : mp) {
    if (e.second == 1) {
      if (flag) {
        t.emplace_back(e.first);
      } else {
        t.emplace_back(24 - e.first);
      }
      flag ^= 1;
    } else {
      t.emplace_back(e.first);
      t.emplace_back(24 - e.first);
    }
  }

  int ans = (int)1e9;

  sort(all(t));
  debug(t);

  for (int i = 0; i < (int)t.size() - 1; ++i)
    ans = min(ans, t[i + 1] - t[i]);
  ans = min(ans, 24 - t.back());

  cout << ans << endl;

  return 0;
}