結果
問題 | No.634 硬貨の枚数1 |
ユーザー | kuwa |
提出日時 | 2018-01-20 00:41:57 |
言語 | Haskell (9.8.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,313 bytes |
コンパイル時間 | 710 ms |
コンパイル使用メモリ | 159,616 KB |
最終ジャッジ日時 | 2024-11-14 20:19:16 |
合計ジャッジ時間 | 1,579 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
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:37:8: error: [GHC-82311] Empty 'do' block Suggested fix: Perhaps you intended to use NondecreasingIndentation | 37 | else do | ^^ Main.hs:53:24: error: [GHC-87543] Ambiguous occurrence ‘BC.getLine’. It could refer to either ‘BC.getLine’, imported qualified from ‘Data.ByteString’ at Main.hs:8:1-38, or ‘BC.getLine’, imported qualified from ‘Data.ByteString.Char8’ at Main.hs:7:1-44. | 53 | readInt = parseInt <$> BC.getLine | ^^^^^^^^^^ Main.hs:56:26: error: [GHC-87543] Ambiguous occurrence ‘BC.getLine’. It could refer to either ‘BC.getLine’, imported qualified from ‘Data.ByteString’ at Main.hs:8:1-38, or ‘BC.getLine’, imported qualified from ‘Data.ByteString.Char8’ at Main.hs:7:1-44. | 56 | readInts = parseInts <$> BC.getLine | ^^^^^^^^^^
ソースコード
module Main where import Control.Monad import Control.Applicative import Data.Maybe import Data.List import qualified Text.Printf import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString as BC import Debug.Trace ------------------------------------------ calc :: Int -> Int calc x = f 0 5000 where f l r | l+1 >= r = l | otherwise = let m = (l+r) `div` 2 in if m*(m+1)`div`2 <= x then f m r else f l m calc2 :: Int -> Maybe Int calc2 n = let xs = filter (== n) $ do a <- takeWhile (< n) $ map (\x -> x*(x+1)`div`2) [0..] let b = calc (n-a) return $ a + b*(b+1)`div`2 in case xs of [] -> Nothing (x:_) -> Just x main :: IO () main = do n <- readInt if n == (let x = calc n in x*(x+1)`div`2) then print 1 else do print $ case calc2 n of Nothing -> 3 Just _ -> 2 ------------------------------------------ {- Int input -} parseInt :: BC.ByteString -> Int parseInt = fst . fromJust . BC.readInt parseInts :: BC.ByteString -> [Int] parseInts = map parseInt <$> BC.words readInt :: IO Int readInt = parseInt <$> BC.getLine readInts :: IO [Int] readInts = parseInts <$> BC.getLine {- Double Formatting -} doubleFmt :: Double -> String doubleFmt = Text.Printf.printf "%.12f"