結果

問題 No.260 世界のなんとか3
ユーザー pekempey
提出日時 2017-01-27 22:11:00
言語 F#
(F# 4.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 1,379 bytes
コンパイル時間 7,613 ms
コンパイル使用メモリ 186,916 KB
実行使用メモリ 40,704 KB
最終ジャッジ日時 2024-12-23 16:01:54
合計ジャッジ時間 13,883 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (250 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

let A, B = System.Console.ReadLine().Split() |> fun a -> a.[0], a.[1]
let LA = String.length A
let LB = String.length B
let L = max LA LB

let a = ((String.replicate (L - LA) "0") + A).ToCharArray()
let b = ((String.replicate (L - LB) "0") + B).ToCharArray()

// pos, (less, more, has3), mod24
let dp = Array3D.zeroCreate (L + 1) 8 24
dp.[0, 0, 0] <- 1

let Pack less more has3 = (less) ||| (more <<< 1) ||| (has3 <<< 2)
let Unpack v = (v &&& 1, v >>> 1 &&& 1, v >>> 2 &&& 1)
let digit c = int c - int '0'

let mo = 1000000007

for i = 0 to L - 1 do
    for j = 0 to 7 do
        let less, more, has3 = Unpack(j)
        for k = 0 to 23 do
            let low = if more = 0 then digit a.[i] else 0
            let high = if less = 0 then digit b.[i] else 9
            for d = low to high do
                let less1 = if less = 1 || d < high then 1 else 0
                let more1 = if more = 1 || d > low then 1 else 0
                let has31 = if has3 = 1 || d = 3 then 1 else 0
                let jj = Pack less1 more1 has31
                let kk = (10 * k + d) % 24
                dp.[i + 1, jj, kk] <- (dp.[i + 1, jj, kk] + dp.[i, j, k]) % mo

let mutable ans = 0

for j = 0 to 7 do
    let _, _, has3 = Unpack(j)
    for k = 0 to 23 do
        if k % 8 <> 0 && (k % 3 = 0 || has3 = 1) then
            ans <- (ans + dp.[L, j, k]) % mo

System.Console.WriteLine(ans)
0