結果
問題 | No.129 お年玉(2) |
ユーザー |
![]() |
提出日時 | 2017-04-22 11:31:08 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 94 ms / 5,000 ms |
コード長 | 782 bytes |
コンパイル時間 | 5,954 ms |
コンパイル使用メモリ | 169,600 KB |
実行使用メモリ | 94,080 KB |
最終ジャッジ日時 | 2024-11-28 00:49:06 |
合計ジャッジ時間 | 9,446 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:10:10: warning: [GHC-63394] [-Wx-partial] In the use of ‘tail’ (imported from Data.List, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 10 | bits = tail (reverse (take w (unfoldr (return . swap . flip divMod 2) x))) | ^^^^ Main.hs:14:6: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Data.List, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 14 | | head bs == 0 = query' left (tail bs) | ^^^^ Main.hs:14:34: warning: [GHC-63394] [-Wx-partial] In the use of ‘tail’ (imported from Data.List, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 14 | | head bs == 0 = query' left (tail bs) | ^^^^ Main.hs:15:32: warning: [GHC-63394] [-Wx-partial] In the use of ‘tail’ (imported from Data.List, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 15 | | otherwise = query' right (tail bs) | ^^^^ [2 of 2] Linking a.out
ソースコード
importData.TupleimportData.Listdata 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 bitswherebits = tail (reverse (take w (unfoldr (return . swap . flip divMod 2) x)))w = floor (logBase 2 (fromIntegral x)) + 1query' (Node v left right) bs| bs == [] = v| head bs == 0 = query' left (tail bs)| otherwise = query' right (tail bs)q = 10^9comb 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 . wordsotoshidama::Integer->Integerotoshidama [n,m] = let r = mod n (1000*m) in mod (comb m (div r 1000)) q