結果

問題 No.260 世界のなんとか3
ユーザー koba-e964koba-e964
提出日時 2017-01-12 00:37:30
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,152 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 11,332 KB
実行使用メモリ 37,028 KB
最終ジャッジ日時 2023-08-23 08:35:04
合計ジャッジ時間 5,631 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
37,028 KB
testcase_01 AC 246 ms
32,476 KB
testcase_02 AC 249 ms
32,484 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a, b = gets.split.map &:to_i
$mod = 10 ** 9 + 7
# http://kmjp.hatenablog.jp/entry/2015/08/03/0930
def solve(x)
  dp = Array.new(10101).map{|_|
    Array.new(2).map{|_|
      Array.new(2).map{|_|
        Array.new(3).map{|_|
          Array.new(8, 0)}}}}
  dp[0][0][0][0][0] = 1
  xs = x.to_s
  n = xs.size
  (0 ... n).each {|d|
    vd = xs[d].ord - 48
    (0..1).each {|more|
      (0..1).each {|i3|
        (0..2).each {|m3|
          (0..7).each {|m8|
            (0..9).each {|x|
              if more == 0 && x > vd
                next
              end
              dp[d+1][more | (x<vd ? 1 : 0)][i3 | (x==3 ? 1 : 0)][(m3*10+x)%3][(m8*10+x)%8] += dp[d][more][i3][m3][m8]
              dp[d+1][more | (x<vd ? 1 : 0)][i3 | (x==3 ? 1 : 0)][(m3*10+x)%3][(m8*10+x)%8] %= $mod # =
            }
          }
        }
      }
    }
  }
  ret = 0
  (0..1).each {|more|
    (0..1).each {|i3|
      (0..2).each {|m3|
        (0..7).each {|m8|
          if (m3 == 0 || i3 == 1) && m8 != 0
            ret += dp[n][more][i3][m3][m8]
            ret %= $mod #=
          end
        }
      }
    }
  }
  ret
end
puts (solve(b) - solve(a - 1) + $mod) % $mod
0