結果

問題 No.260 世界のなんとか3
ユーザー rimorimo39rimorimo39
提出日時 2020-02-13 02:08:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 4,191 bytes
コンパイル時間 2,775 ms
コンパイル使用メモリ 189,040 KB
実行使用メモリ 32,896 KB
最終ジャッジ日時 2024-04-15 03:51:59
合計ジャッジ時間 6,286 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 145 ms
32,896 KB
testcase_04 AC 145 ms
32,768 KB
testcase_05 AC 63 ms
14,080 KB
testcase_06 AC 39 ms
10,496 KB
testcase_07 AC 133 ms
28,544 KB
testcase_08 AC 148 ms
28,928 KB
testcase_09 AC 72 ms
15,744 KB
testcase_10 AC 114 ms
25,984 KB
testcase_11 AC 145 ms
30,336 KB
testcase_12 AC 116 ms
23,936 KB
testcase_13 AC 20 ms
7,424 KB
testcase_14 AC 137 ms
28,672 KB
testcase_15 AC 27 ms
8,960 KB
testcase_16 AC 98 ms
23,808 KB
testcase_17 AC 78 ms
18,432 KB
testcase_18 AC 67 ms
16,512 KB
testcase_19 AC 142 ms
28,800 KB
testcase_20 AC 87 ms
19,200 KB
testcase_21 AC 92 ms
20,992 KB
testcase_22 AC 99 ms
24,832 KB
testcase_23 AC 10 ms
6,944 KB
testcase_24 AC 130 ms
26,368 KB
testcase_25 AC 206 ms
32,896 KB
testcase_26 AC 139 ms
32,896 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 138 ms
32,896 KB
testcase_29 AC 135 ms
32,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;

#if __cplusplus < 201103L
#error C++11 or higher expected.
#endif
constexpr int CPPV = (__cplusplus / 100 % 100); // C++ Version

// define
#define endl "\n"
#ifdef LOCAL
#define lout cerr
#else
ostream devnull(0);
#define lout devnull
#endif
#define dump(x) lout << #x << " = " << (x) << endl;

#define all(a) (a).begin(), (a).end()

// rep
// Inspired by:
// https://github.com/kurokoji/.cpp-Template/blob/master/template/template2.cpp
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...)                                 \
  GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1) \
  (__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, d) rep5(i, a, n, d, <)
#define rep5(i, a, n, d, o) \
  for (auto i = decltype(n)(a), i##_len = (n); i o i##_len; i += (d))

#define rrep(...)                                    \
  GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1) \
  (__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, -1)
#define rrep4(i, a, n, d) rep5(i, (a)-1, n, d, >=)

#define repc(...)                                    \
  GET_MACRO(__VA_ARGS__, repc4, repc3, repc2, repc1) \
  (__VA_ARGS__)
#define repc1(n) repc2(_, n)
#define repc2(i, n) repc3(i, 0, n)
#define repc3(i, a, n) repc4(i, a, n, 1)
#define repc4(i, a, n, d) rep5(i, a, n, d, <=)

// alias
using ll = long long;
using lint = long long;

// func
template <class C>
void vcin(C &c)
{
  for (auto &&a : c)
  {
    cin >> a;
  }
}
template <class C, class D>
void vcin(C &c, D &d)
{
  for (auto it1 = c.begin(), it2 = d.begin(); it1 != c.end() && it2 != d.end();
       it1++, it2++)
  {
    cin >> *it1 >> *it2;
  }
}
template <class C>
void vcout(const C &c, const string delimiter = " ")
{
  for (auto it = c.begin(); it != c.end(); it++)
  {
    if (it != c.begin())
      cout << delimiter;
    cout << *it;
  }
}
template <class T = int>
inline T input()
{
  T x;
  cin >> x;
  return (x);
}
template <typename T>
inline void chmax(T &x, const T y)
{
  if (x < y)
    x = y;
}
template <typename T>
inline void chmin(T &x, const T y)
{
  if (x > y)
    x = y;
}

#if 1
// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v)
{
  t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v)
{
  for (auto &e : t)
    fill_v(e, v);
}
#endif

constexpr int INF = 1 << 24;
constexpr lint LINF = 1LL << 48;

inline lint bit(int n)
{
  return 1LL << n;
}

inline bool bitof(lint n, int i)
{
  return (n >> i) & 1;
}

template <typename T>
inline bool between(T a, T x, T b)
{
  return a <= x && x <= b;
}

void solve();

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  solve();

  return 0;
}

void solve()
{
  constexpr int MOD = (int)1e9 + 7;

  string A, B;
  cin >> A >> B;

  const int n = B.size();

  vector<int> a(n), b;

  rep(i, A.size())
  {
    a[i - A.size() + n] = A[i] - '0';
  }

  b.reserve(n);
  for (char c : B)
  {
    b.push_back(c - '0');
  }

#ifdef LOCAL
  vcout(a, " ");
  cout << endl;
  vcout(b, " ");
  cout << endl;
#endif

  auto dp = make_v<lint>(n + 1, 2, 2, 2, 3, 8);

  dp[0][0][0][0][0][0] = 1;

  rep(i, n) repc(j, 1) repc(k, 1) repc(l, 1) rep(m, 3) rep(o, 8) repc(d, j ? 0 : a[i], k ? 9 : b[i])
  {
    dp[i + 1][j || d > a[i]][k || d < b[i]][l || d == 3][(m + d) % 3][(o * 10 + d) % 8] += dp[i][j][k][l][m][o];
    dp[i + 1][j || d > a[i]][k || d < b[i]][l || d == 3][(m + d) % 3][(o * 10 + d) % 8] %= MOD;
  }

  lint ans = 0;
  repc(j, 1) repc(k, 1) repc(l, 1) rep(m, 3) rep(o, 8)
  {
    if ((l || m == 0) && o != 0)
    {
      ans += dp[n][j][k][l][m][o];
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
0