結果

問題 No.260 世界のなんとか3
ユーザー oevloevl
提出日時 2019-03-12 12:30:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 168,656 KB
実行使用メモリ 11,196 KB
最終ジャッジ日時 2023-09-05 20:20:33
合計ジャッジ時間 4,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,944 KB
testcase_01 AC 5 ms
10,900 KB
testcase_02 AC 5 ms
11,196 KB
testcase_03 AC 116 ms
11,112 KB
testcase_04 AC 117 ms
10,948 KB
testcase_05 AC 27 ms
11,028 KB
testcase_06 AC 19 ms
10,852 KB
testcase_07 AC 81 ms
10,912 KB
testcase_08 AC 58 ms
10,976 KB
testcase_09 AC 34 ms
11,152 KB
testcase_10 AC 90 ms
10,936 KB
testcase_11 AC 85 ms
10,892 KB
testcase_12 AC 54 ms
10,912 KB
testcase_13 AC 19 ms
10,896 KB
testcase_14 AC 77 ms
10,936 KB
testcase_15 AC 24 ms
11,196 KB
testcase_16 AC 69 ms
10,900 KB
testcase_17 AC 56 ms
11,044 KB
testcase_18 AC 53 ms
10,924 KB
testcase_19 AC 67 ms
11,044 KB
testcase_20 AC 49 ms
10,912 KB
testcase_21 AC 44 ms
10,964 KB
testcase_22 AC 77 ms
11,032 KB
testcase_23 AC 12 ms
10,880 KB
testcase_24 AC 61 ms
10,968 KB
testcase_25 AC 79 ms
10,960 KB
testcase_26 AC 45 ms
10,920 KB
testcase_27 AC 5 ms
10,992 KB
testcase_28 AC 84 ms
11,080 KB
testcase_29 AC 151 ms
10,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
#define MOD 1000000007

template <class T> void add(T &a, T b) { a = (a + b) % MOD; }

ll solve(string S) {
  ll dp[10005][2][3][8][2] = {};
  dp[0][0][0][0][0] = 1;
  int len = S.size();
  rep(i, len) rep(j, 2) rep(k, 3) rep(l, 8) rep(m, 2) {
    int x = j ? 9 : S[i] - '0';
    rep(d, x + 1) {
      add(dp[i + 1][j || d < x][(k + d) % 3][(10 * l + d) % 8][m || d == 3],
          dp[i][j][k][l][m]);
    }
  }
  ll ans = 0;
  rep(j, 2) rep(k, 3) rep(l, 8) rep(m, 2) {
    if (l == 0)
      continue;
    if (k == 0 || m)
      add(ans, dp[len][j][k][l][m]);
  }
  return ans;
}

int main() {
  string A, B;
  cin >> A >> B;
  int a = A[A.size() - 1] - '0';
  A = A.substr(0, A.size() - 1);
  A += ('0' + a - 1);
  ll ans = solve(B) - solve(A) + MOD;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}
0