結果

問題 No.1106 🦉 何事もバランスが大事
ユーザー KoDKoD
提出日時 2020-07-03 23:13:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 2,701 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 79,528 KB
実行使用メモリ 6,320 KB
最終ジャッジ日時 2023-10-17 06:14:55
合計ジャッジ時間 3,734 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 7 ms
6,320 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 4 ms
6,316 KB
testcase_12 AC 4 ms
6,320 KB
testcase_13 AC 5 ms
6,320 KB
testcase_14 AC 5 ms
6,320 KB
testcase_15 AC 5 ms
6,320 KB
testcase_16 AC 6 ms
6,320 KB
testcase_17 AC 5 ms
6,320 KB
testcase_18 AC 5 ms
6,320 KB
testcase_19 AC 5 ms
6,320 KB
testcase_20 AC 5 ms
6,320 KB
testcase_21 AC 6 ms
6,320 KB
testcase_22 AC 6 ms
6,320 KB
testcase_23 AC 6 ms
6,320 KB
testcase_24 AC 7 ms
6,320 KB
testcase_25 AC 7 ms
6,320 KB
testcase_26 AC 7 ms
6,320 KB
testcase_27 AC 7 ms
6,320 KB
testcase_28 AC 7 ms
6,320 KB
testcase_29 AC 7 ms
6,320 KB
testcase_30 AC 7 ms
6,320 KB
testcase_31 AC 7 ms
6,320 KB
testcase_32 AC 7 ms
6,320 KB
testcase_33 AC 7 ms
6,320 KB
testcase_34 AC 7 ms
6,320 KB
testcase_35 AC 7 ms
6,320 KB
testcase_36 AC 7 ms
6,320 KB
testcase_37 AC 7 ms
6,320 KB
testcase_38 AC 7 ms
6,320 KB
testcase_39 AC 7 ms
6,320 KB
testcase_40 AC 7 ms
6,320 KB
testcase_41 AC 7 ms
6,320 KB
testcase_42 AC 7 ms
6,320 KB
testcase_43 AC 7 ms
6,320 KB
testcase_44 AC 7 ms
6,320 KB
testcase_45 AC 8 ms
6,320 KB
testcase_46 AC 7 ms
6,320 KB
testcase_47 AC 8 ms
6,320 KB
testcase_48 AC 7 ms
6,320 KB
testcase_49 AC 8 ms
6,320 KB
testcase_50 AC 7 ms
6,320 KB
testcase_51 AC 7 ms
6,320 KB
testcase_52 AC 7 ms
6,320 KB
testcase_53 AC 7 ms
6,320 KB
testcase_54 AC 7 ms
6,320 KB
testcase_55 AC 7 ms
6,320 KB
testcase_56 AC 7 ms
6,320 KB
testcase_57 AC 8 ms
6,320 KB
testcase_58 AC 7 ms
6,320 KB
testcase_59 AC 7 ms
6,320 KB
testcase_60 AC 8 ms
6,320 KB
testcase_61 AC 8 ms
6,320 KB
testcase_62 AC 7 ms
6,320 KB
testcase_63 AC 8 ms
6,320 KB
testcase_64 AC 7 ms
6,320 KB
testcase_65 AC 7 ms
6,320 KB
testcase_66 AC 7 ms
6,320 KB
testcase_67 AC 7 ms
6,320 KB
testcase_68 AC 7 ms
6,320 KB
testcase_69 AC 8 ms
6,320 KB
testcase_70 AC 8 ms
6,320 KB
testcase_71 AC 7 ms
6,320 KB
testcase_72 AC 7 ms
6,320 KB
testcase_73 AC 8 ms
6,320 KB
testcase_74 AC 7 ms
6,320 KB
testcase_75 AC 7 ms
6,320 KB
testcase_76 AC 7 ms
6,320 KB
testcase_77 AC 7 ms
6,320 KB
testcase_78 AC 7 ms
6,320 KB
testcase_79 AC 8 ms
6,320 KB
testcase_80 AC 7 ms
6,320 KB
testcase_81 AC 7 ms
6,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

i64 dp[30][3000][2][2];

int main() {
  i64 N;
  std::cin >> N;
  ++N;
  std::vector<i64> digit;
  {
    i64 n = N;
    while (n > 0) {
      i64 r = n % 5;
      digit.push_back(r);
      n /= 5;
      if (r >= 3) {
        digit.back() -= 5;
        ++n;
      }
    }
    std::reverse(digit.begin(), digit.end());
  }
  size_t size = digit.size();
  dp[0][1500][0][0] = 1;
  for (auto i: range(0, size)) {
    for (auto j: range(0, 3000)) {
      for (auto l: { 0, 1 }) {
        for (auto c: { -2, -1, 0, 1, 2 }) {
          if (j + c < 0 || j + c >= 3000 || (l == 0 && c < 0)) {
            continue;
          }
          auto nl = l;
          if (c > 0) {
            nl = 1;
          }
          for (auto k: { 0, 1 }) {
            if (k == 0 && c > digit[i]) {
              continue;
            }
            auto nk = k;
            if (c < digit[i]) {
              nk = 1;
            }
            dp[i + 1][j + c][nk][nl] += dp[i][j][k][l];
          }
        }
      }
    }
  }
  std::cout << dp[size][1500][1][1] << '\n';
  return 0;
}
0