結果

問題 No.1035 Color Box
ユーザー ikdikd
提出日時 2020-05-02 02:17:16
言語 F#
(.NET 7)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,249 bytes
コンパイル時間 4,781 ms
コンパイル使用メモリ 165,924 KB
実行使用メモリ 38,876 KB
最終ジャッジ日時 2023-08-26 20:58:24
合計ジャッジ時間 10,667 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
36,764 KB
testcase_01 AC 81 ms
23,756 KB
testcase_02 AC 83 ms
20,964 KB
testcase_03 AC 85 ms
23,440 KB
testcase_04 AC 107 ms
35,252 KB
testcase_05 AC 85 ms
24,736 KB
testcase_06 AC 83 ms
23,048 KB
testcase_07 AC 107 ms
36,760 KB
testcase_08 AC 143 ms
38,812 KB
testcase_09 AC 119 ms
36,808 KB
testcase_10 AC 89 ms
28,836 KB
testcase_11 AC 80 ms
23,100 KB
testcase_12 AC 82 ms
25,528 KB
testcase_13 AC 142 ms
36,776 KB
testcase_14 AC 145 ms
38,876 KB
testcase_15 AC 151 ms
36,936 KB
testcase_16 AC 80 ms
25,024 KB
testcase_17 AC 79 ms
22,964 KB
testcase_18 AC 76 ms
23,064 KB
testcase_19 AC 149 ms
36,804 KB
testcase_20 AC 80 ms
20,984 KB
testcase_21 AC 79 ms
23,100 KB
testcase_22 AC 79 ms
23,096 KB
testcase_23 AC 81 ms
20,984 KB
testcase_24 AC 81 ms
23,140 KB
testcase_25 AC 80 ms
23,072 KB
testcase_26 AC 82 ms
25,160 KB
testcase_27 AC 79 ms
23,120 KB
testcase_28 AC 82 ms
25,104 KB
testcase_29 AC 79 ms
25,016 KB
testcase_30 AC 80 ms
25,160 KB
testcase_31 AC 79 ms
23,024 KB
testcase_32 AC 81 ms
25,160 KB
testcase_33 AC 82 ms
23,112 KB
testcase_34 AC 81 ms
22,980 KB
testcase_35 AC 83 ms
23,060 KB
testcase_36 AC 82 ms
23,036 KB
testcase_37 AC 80 ms
23,024 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(15,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 mutable fact = [n; m] |> List.max |> Array.create 1
    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