結果

問題 No.260 世界のなんとか3
ユーザー nebukuro09nebukuro09
提出日時 2016-11-22 18:58:59
言語 D
(dmd 2.105.2)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 3,219 ms
コンパイル使用メモリ 156,112 KB
実行使用メモリ 37,852 KB
最終ジャッジ日時 2023-09-02 23:03:57
合計ジャッジ時間 9,616 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 427 ms
36,832 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 109 ms
11,696 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 184 ms
18,180 KB
testcase_13 WA -
testcase_14 AC 273 ms
24,528 KB
testcase_15 AC 73 ms
8,448 KB
testcase_16 AC 239 ms
22,780 KB
testcase_17 WA -
testcase_18 AC 184 ms
17,880 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 211 ms
20,256 KB
testcase_25 AC 260 ms
19,972 KB
testcase_26 AC 162 ms
20,408 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 423 ms
37,108 KB
testcase_29 AC 523 ms
36,076 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)
              {//writeln(d);
              (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; 0..8)
          if ((k == 0 || l > 0) && m > 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];
  //writeln(solve(B));
  //writeln(solve(A));
  writeln(solve(B)-solve(A));
}
0