結果

問題 No.688 E869120 and Constructing Array 2
ユーザー ducktail
提出日時 2018-05-19 00:00:16
言語 Haskell
(9.10.1)
結果
WA  
実行時間 -
コード長 521 bytes
コンパイル時間 7,446 ms
コンパイル使用メモリ 169,984 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 13:42:12
合計ジャッジ時間 7,673 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative ((<$>))
import Data.List (intercalate)

main :: IO ()
main = solve <$> readLn >>= mapM_ putStrLn

solve :: Int -> [String]
solve 0 = ["1", "0"]
solve 1 = ["2", "1 1"]
solve k = let l = g 0 k in [show . length $ l, intercalate " " . map show $ l]
  where f x = let y = ceiling . sqrt . (* 2) . fromIntegral $ x in if 2 * x == y * (y-1) then Just y else Nothing
        g z x = case f x of
                 Just i -> replicate z 0 ++ replicate i 1
                 Nothing -> g (z+1) (x `div` 2)
0