結果

問題 No.260 世界のなんとか3
ユーザー nebukuro09nebukuro09
提出日時 2016-11-22 19:15:17
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 524 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 156,184 KB
実行使用メモリ 37,404 KB
最終ジャッジ日時 2023-09-02 23:04:33
合計ジャッジ時間 8,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 423 ms
36,660 KB
testcase_04 AC 425 ms
36,412 KB
testcase_05 AC 81 ms
10,704 KB
testcase_06 AC 52 ms
6,796 KB
testcase_07 AC 285 ms
25,716 KB
testcase_08 AC 198 ms
19,660 KB
testcase_09 AC 108 ms
11,944 KB
testcase_10 AC 326 ms
28,696 KB
testcase_11 AC 301 ms
28,848 KB
testcase_12 AC 181 ms
17,384 KB
testcase_13 AC 51 ms
6,872 KB
testcase_14 AC 271 ms
24,324 KB
testcase_15 AC 72 ms
8,440 KB
testcase_16 AC 240 ms
22,564 KB
testcase_17 AC 191 ms
19,016 KB
testcase_18 AC 184 ms
18,460 KB
testcase_19 AC 234 ms
21,688 KB
testcase_20 AC 167 ms
16,128 KB
testcase_21 AC 145 ms
14,324 KB
testcase_22 AC 275 ms
24,276 KB
testcase_23 AC 26 ms
4,892 KB
testcase_24 AC 210 ms
20,572 KB
testcase_25 AC 262 ms
20,528 KB
testcase_26 AC 158 ms
19,860 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 420 ms
36,636 KB
testcase_29 AC 524 ms
37,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;
import std.bigint;


long mod = 10L^^9+7;

long solve(string S) {
  auto N = S.length;
  auto dp = new long[][][][][](N+1, 2, 3, 2, 8); // keta, miman, 3wareru, 3tsuku, 8wareru
  dp[0][0][0][0][0] = 1L;
  foreach (i; 0..N)
    foreach (j; 0..2)
      foreach (k; 0..3)
        foreach (l; 0..2)
          foreach (m; 0..8) {
            auto digit = j ? 9 : (S[i]-'0').to!int;
            foreach (d; 0..digit+1)
              (dp[i+1][j||(d<digit)][(k+d)%3][l||(d==3)][(10*m+d)%8] += 
               dp[i][j][k][l][m]) %= mod;
          }

  long ans = 0;
  foreach (j; 0..2)
    foreach (k; 0..3)
      foreach (l; 0..2)
        foreach (m; 1..8)
          if (k == 0 || l > 0)
            (ans += dp[N][j][k][l][m]) %= mod;

  return ans;
  
}

void main() {
  auto input = readln.split;
  auto A = (BigInt(input[0]) - BigInt(1)).to!string;
  auto B = input[1];
  auto ans = (solve(B) - solve(A)) % mod;
  writeln(ans < 0 ? mod + ans : ans);
}
0