結果

問題 No.1035 Color Box
ユーザー ikdikd
提出日時 2020-05-02 02:26:21
言語 F#
(F# 4.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,191 bytes
コンパイル時間 3,675 ms
コンパイル使用メモリ 170,372 KB
実行使用メモリ 38,880 KB
最終ジャッジ日時 2023-08-26 21:14:13
合計ジャッジ時間 9,168 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
36,840 KB
testcase_01 AC 89 ms
23,728 KB
testcase_02 AC 87 ms
23,052 KB
testcase_03 AC 92 ms
23,432 KB
testcase_04 AC 111 ms
35,140 KB
testcase_05 AC 93 ms
26,860 KB
testcase_06 AC 84 ms
21,072 KB
testcase_07 AC 111 ms
34,744 KB
testcase_08 AC 154 ms
36,792 KB
testcase_09 AC 128 ms
34,704 KB
testcase_10 AC 96 ms
28,840 KB
testcase_11 AC 88 ms
25,096 KB
testcase_12 AC 88 ms
23,392 KB
testcase_13 AC 148 ms
38,848 KB
testcase_14 AC 154 ms
38,876 KB
testcase_15 AC 161 ms
36,828 KB
testcase_16 AC 85 ms
23,028 KB
testcase_17 AC 86 ms
25,068 KB
testcase_18 AC 83 ms
23,092 KB
testcase_19 AC 155 ms
38,880 KB
testcase_20 AC 86 ms
23,016 KB
testcase_21 AC 84 ms
20,908 KB
testcase_22 AC 85 ms
23,072 KB
testcase_23 AC 85 ms
21,048 KB
testcase_24 AC 87 ms
25,060 KB
testcase_25 AC 86 ms
23,000 KB
testcase_26 AC 86 ms
25,032 KB
testcase_27 AC 86 ms
23,096 KB
testcase_28 AC 86 ms
21,000 KB
testcase_29 AC 86 ms
23,016 KB
testcase_30 AC 86 ms
22,968 KB
testcase_31 AC 86 ms
23,024 KB
testcase_32 AC 87 ms
23,032 KB
testcase_33 AC 85 ms
23,008 KB
testcase_34 AC 84 ms
21,048 KB
testcase_35 AC 86 ms
23,000 KB
testcase_36 AC 86 ms
23,044 KB
testcase_37 AC 84 ms
25,068 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

/home/judge/data/code/Main.fs(12,9): warning FS0025: Incomplete pattern matches on this expression. For example, the value '[|_; _; _|]' may indicate a case not covered by the pattern(s).

ソースコード

diff #

// Learn more about F# at http://fsharp.org

open System

let rec mpow (a: int64) x m =
    if x = 1L then a
    elif x % 2L = 0L then mpow (a * a % m) (x / 2L) m
    else a * mpow a (x - 1L) m % m

[<EntryPoint>]
let main argv =
    let [| n; m |] = stdin.ReadLine().Split() |> Array.map int
    let l = [ n; m ] |> List.max
    let mo = 1000000007L
    let fact =
        Array.concat
            [ [| 1L |]
              [| for i in 1L .. int64 (l) -> i |] ]
        |> Array.mapFold (fun acc x -> acc * x % mo, acc * x % mo) 1L
        |> fst
    let inv =
        Array.concat
            [ [| for i in 1L .. int64 (l) -> i |]
              [| 1L |] ]
        |> Array.rev
        |> Array.mapFold (fun acc x -> acc * x % mo, acc * x % mo) (mpow fact.[l] (mo - 2L) mo)
        |> fst
        |> Array.rev

    let binom a b = fact.[a] * inv.[b] % mo * inv.[a - b] % mo
    let mutable ans = 0L
    for i = m downto 1 do
        if (m - i) % 2 = 0
        then ans <- (ans + (binom m i) * (mpow (i |> int64) (n |> int64) mo) % mo) % mo
        else ans <- (ans - (binom m i) * (mpow (i |> int64) (n |> int64) mo) % mo + mo) % mo
    printfn "%d" ans
    0 // return an integer exit code
0