結果

問題 No.129 お年玉(2)
ユーザー aimyaimy
提出日時 2017-04-22 11:31:08
言語 Haskell
(9.8.2)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 782 bytes
コンパイル時間 8,602 ms
コンパイル使用メモリ 162,000 KB
実行使用メモリ 97,088 KB
最終ジャッジ日時 2023-08-18 17:52:37
合計ジャッジ時間 10,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
13,196 KB
testcase_01 AC 93 ms
97,088 KB
testcase_02 AC 3 ms
7,156 KB
testcase_03 AC 3 ms
7,164 KB
testcase_04 AC 3 ms
7,120 KB
testcase_05 AC 42 ms
38,784 KB
testcase_06 AC 52 ms
51,176 KB
testcase_07 AC 52 ms
44,552 KB
testcase_08 AC 52 ms
58,456 KB
testcase_09 AC 65 ms
69,464 KB
testcase_10 AC 63 ms
51,888 KB
testcase_11 AC 52 ms
46,672 KB
testcase_12 AC 64 ms
69,420 KB
testcase_13 AC 64 ms
71,696 KB
testcase_14 AC 53 ms
53,256 KB
testcase_15 AC 52 ms
48,576 KB
testcase_16 AC 52 ms
47,704 KB
testcase_17 AC 64 ms
68,960 KB
testcase_18 AC 52 ms
52,432 KB
testcase_19 AC 74 ms
69,156 KB
testcase_20 AC 52 ms
52,140 KB
testcase_21 AC 74 ms
70,892 KB
testcase_22 AC 53 ms
51,172 KB
testcase_23 AC 84 ms
84,312 KB
testcase_24 AC 75 ms
73,720 KB
testcase_25 AC 52 ms
39,356 KB
testcase_26 AC 52 ms
54,992 KB
testcase_27 AC 52 ms
49,668 KB
testcase_28 AC 74 ms
68,432 KB
testcase_29 AC 2 ms
7,120 KB
testcase_30 AC 2 ms
7,220 KB
testcase_31 AC 2 ms
7,432 KB
testcase_32 AC 3 ms
7,304 KB
testcase_33 AC 4 ms
8,448 KB
testcase_34 AC 4 ms
7,988 KB
testcase_35 AC 4 ms
8,468 KB
testcase_36 AC 4 ms
8,696 KB
testcase_37 AC 4 ms
8,892 KB
testcase_38 AC 12 ms
14,172 KB
testcase_39 AC 22 ms
25,660 KB
testcase_40 AC 52 ms
49,696 KB
testcase_41 AC 33 ms
26,192 KB
testcase_42 AC 22 ms
19,464 KB
testcase_43 AC 22 ms
19,472 KB
testcase_44 AC 93 ms
96,696 KB
testcase_45 AC 12 ms
13,376 KB
testcase_46 AC 32 ms
27,852 KB
testcase_47 AC 83 ms
93,876 KB
testcase_48 AC 62 ms
61,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Tuple
import Data.List

data Tree a = Node a (Tree a) (Tree a)
memoize f = memof where memof = f (query (blank memof))
blank f = blank' 1 where blank' k = Node (f k) (blank' (2*k)) (blank' (2*k+1))

query m x = query' m bits
 where
  bits = tail (reverse (take w (unfoldr (return . swap . flip divMod 2) x)))
  w = floor (logBase 2 (fromIntegral x)) + 1
  query' (Node v left right) bs
   | bs == [] = v
   | head bs == 0 = query' left (tail bs)
   | otherwise = query' right (tail bs)

q = 10^9

comb n r = div (fact n) (fact r * fact (n-r))
fact = memoize (\f x -> if x<=1 then 1 else x * f (x-1))

main = getContents >>= print . otoshidama . map read . words

otoshidama :: [Integer] -> Integer
otoshidama [n,m] = let r = mod n (1000*m) in mod (comb m (div r 1000)) q
0