結果

問題 No.260 世界のなんとか3
ユーザー nebukuro09nebukuro09
提出日時 2016-11-22 18:39:22
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 154,184 KB
実行使用メモリ 21,620 KB
最終ジャッジ日時 2023-09-02 23:03:35
合計ジャッジ時間 11,539 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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;


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] = 1;
  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)][(m+d)%8] += 
               dp[i][j][k][l][m]) %= mod;
          }

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

  writeln(dp);
  return ans;
}

void main() {
  auto input = readln.split;
  auto A = input[0];
  auto B = input[1];
  writeln(solve(B));
  //writeln(solve(A));
  //writeln(solve(B)-solve(A));
}
0