結果

問題 No.4 おもりと天秤
ユーザー myuonmyuon
提出日時 2015-03-09 09:09:08
言語 Haskell
(9.6.2)
結果
AC  
実行時間 2,743 ms / 5,000 ms
コード長 506 bytes
コンパイル時間 3,909 ms
コンパイル使用メモリ 163,620 KB
実行使用メモリ 99,868 KB
最終ジャッジ日時 2023-09-08 16:13:39
合計ジャッジ時間 21,893 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,412 KB
testcase_01 AC 2 ms
7,488 KB
testcase_02 AC 5 ms
9,280 KB
testcase_03 AC 3 ms
7,776 KB
testcase_04 AC 6 ms
10,368 KB
testcase_05 AC 2,274 ms
86,468 KB
testcase_06 AC 3 ms
7,364 KB
testcase_07 AC 2,593 ms
97,772 KB
testcase_08 AC 5 ms
9,556 KB
testcase_09 AC 5 ms
9,660 KB
testcase_10 AC 2,404 ms
86,536 KB
testcase_11 AC 3 ms
7,512 KB
testcase_12 AC 3 ms
7,416 KB
testcase_13 AC 3 ms
7,412 KB
testcase_14 AC 2 ms
7,380 KB
testcase_15 AC 3 ms
7,372 KB
testcase_16 AC 2 ms
7,684 KB
testcase_17 AC 2 ms
7,408 KB
testcase_18 AC 1,043 ms
54,824 KB
testcase_19 AC 2,284 ms
85,556 KB
testcase_20 AC 2,743 ms
99,868 KB
testcase_21 AC 2,453 ms
92,688 KB
testcase_22 AC 2,413 ms
94,608 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 $ ws
0