結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2017-01-27 22:11:00
言語 F#
(F# 4.0)
結果
AC  
実行時間 637 ms / 2,000 ms
コード長 1,379 bytes
コンパイル時間 4,188 ms
コンパイル使用メモリ 161,332 KB
実行使用メモリ 33,752 KB
最終ジャッジ日時 2023-08-25 03:51:26
合計ジャッジ時間 13,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
22,044 KB
testcase_01 AC 57 ms
23,912 KB
testcase_02 AC 58 ms
22,020 KB
testcase_03 AC 448 ms
33,652 KB
testcase_04 AC 448 ms
31,628 KB
testcase_05 AC 221 ms
24,644 KB
testcase_06 AC 164 ms
23,688 KB
testcase_07 AC 386 ms
30,504 KB
testcase_08 AC 447 ms
32,628 KB
testcase_09 AC 244 ms
27,240 KB
testcase_10 AC 324 ms
29,896 KB
testcase_11 AC 416 ms
31,036 KB
testcase_12 AC 359 ms
29,292 KB
testcase_13 AC 107 ms
25,008 KB
testcase_14 AC 397 ms
30,548 KB
testcase_15 AC 126 ms
25,364 KB
testcase_16 AC 323 ms
25,284 KB
testcase_17 AC 250 ms
25,792 KB
testcase_18 AC 217 ms
27,456 KB
testcase_19 AC 417 ms
32,536 KB
testcase_20 AC 274 ms
28,132 KB
testcase_21 AC 314 ms
26,544 KB
testcase_22 AC 318 ms
29,500 KB
testcase_23 AC 80 ms
22,408 KB
testcase_24 AC 388 ms
25,936 KB
testcase_25 AC 637 ms
31,680 KB
testcase_26 AC 384 ms
33,648 KB
testcase_27 AC 57 ms
21,912 KB
testcase_28 AC 430 ms
33,692 KB
testcase_29 AC 428 ms
33,752 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

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