結果

問題 No.4 おもりと天秤
ユーザー e7a894e7a894
提出日時 2018-05-22 14:28:45
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,062 ms / 5,000 ms
コード長 421 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 164,656 KB
実行使用メモリ 21,572 KB
最終ジャッジ日時 2023-09-11 01:12:38
合計ジャッジ時間 6,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,080 KB
testcase_01 AC 3 ms
6,952 KB
testcase_02 AC 12 ms
11,284 KB
testcase_03 AC 2 ms
7,556 KB
testcase_04 AC 6 ms
11,072 KB
testcase_05 AC 642 ms
18,256 KB
testcase_06 AC 2 ms
7,152 KB
testcase_07 AC 702 ms
20,832 KB
testcase_08 AC 3 ms
7,352 KB
testcase_09 AC 3 ms
8,212 KB
testcase_10 AC 772 ms
21,572 KB
testcase_11 AC 3 ms
7,336 KB
testcase_12 AC 3 ms
7,084 KB
testcase_13 AC 2 ms
7,116 KB
testcase_14 AC 2 ms
7,128 KB
testcase_15 AC 2 ms
7,172 KB
testcase_16 AC 3 ms
7,224 KB
testcase_17 AC 2 ms
7,104 KB
testcase_18 AC 1,062 ms
15,152 KB
testcase_19 AC 512 ms
17,644 KB
testcase_20 AC 472 ms
17,944 KB
testcase_21 AC 493 ms
17,532 KB
testcase_22 AC 472 ms
17,880 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 Data.List

main = do
  n <- readLn :: IO Int
  ws <- (map read . words) <$> getLine
  let e = (sum ws) `div` 2
  let ws' = filter (<= e) ws
  putStrLn $ if odd $ sum ws then "impossible" else resolve e ws'

resolve e ws = resolve' [0] ws
  where
    resolve' :: [Int] -> [Int] -> String
    resolve' r [] = if e `elem` r then "possible" else "impossible"
    resolve' r (x:xs) = resolve' (union r (map (+ x) r)) xs
0