結果

問題 No.4 おもりと天秤
ユーザー myuonmyuon
提出日時 2015-03-09 09:11:41
言語 Haskell
(9.8.2)
結果
AC  
実行時間 2,244 ms / 5,000 ms
コード長 537 bytes
コンパイル時間 8,482 ms
コンパイル使用メモリ 163,860 KB
実行使用メモリ 107,416 KB
最終ジャッジ日時 2023-09-08 16:11:25
合計ジャッジ時間 17,694 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,508 KB
testcase_01 AC 3 ms
7,468 KB
testcase_02 AC 4 ms
8,984 KB
testcase_03 AC 3 ms
7,960 KB
testcase_04 AC 6 ms
9,812 KB
testcase_05 AC 1,655 ms
79,564 KB
testcase_06 AC 3 ms
7,500 KB
testcase_07 AC 1,985 ms
95,852 KB
testcase_08 AC 5 ms
9,636 KB
testcase_09 AC 5 ms
9,772 KB
testcase_10 AC 1,665 ms
87,524 KB
testcase_11 AC 3 ms
7,508 KB
testcase_12 AC 3 ms
7,444 KB
testcase_13 AC 3 ms
7,588 KB
testcase_14 AC 3 ms
7,456 KB
testcase_15 AC 2 ms
7,532 KB
testcase_16 AC 3 ms
7,624 KB
testcase_17 AC 2 ms
7,484 KB
testcase_18 AC 862 ms
47,620 KB
testcase_19 AC 1,894 ms
78,392 KB
testcase_20 AC 2,244 ms
107,416 KB
testcase_21 AC 1,952 ms
96,956 KB
testcase_22 AC 2,024 ms
86,560 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 Control.Applicative
import Data.List
import qualified Data.Map as M

solve ws = if M.null $ solve' ws then "impossible" else "possible"

solve' ws = M.filterWithKey (\(_,w) _ -> w*2 == sum ws) $ last $ unfoldr go (ws, M.singleton (0,0) True) where
  go ([],m) = Nothing
  go (x:xs,m) = let m' = M.union m $ M.fromList $ fmap (\((k,w),v) -> ((k+1,w+x),v)) $ M.assocs m in Just $ (m', (xs,m'))

main = do
  _ <- getLine
  ws <- fmap (read :: String -> Int) . words <$> getLine
  putStrLn $ solve $ sortBy (\x y -> compare y x) $ ws
0