結果

問題 No.4 おもりと天秤
ユーザー LeonardoneLeonardone
提出日時 2015-11-01 19:53:16
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 12,868 ms
コンパイル使用メモリ 161,424 KB
実行使用メモリ 8,056 KB
最終ジャッジ日時 2023-10-11 07:51:23
合計ジャッジ時間 13,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,504 KB
testcase_01 AC 3 ms
7,420 KB
testcase_02 AC 2 ms
7,464 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
7,492 KB
testcase_07 WA -
testcase_08 AC 2 ms
7,740 KB
testcase_09 AC 3 ms
7,924 KB
testcase_10 WA -
testcase_11 AC 2 ms
7,468 KB
testcase_12 AC 3 ms
7,536 KB
testcase_13 AC 2 ms
7,376 KB
testcase_14 AC 3 ms
7,560 KB
testcase_15 AC 3 ms
7,424 KB
testcase_16 WA -
testcase_17 AC 2 ms
7,440 KB
testcase_18 AC 3 ms
7,912 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

-- yukicoder My Practice
-- author: Leonardone @ NEETSDKASU
-- http://yukicoder.me/problems/19

import Data.List
import qualified Data.Set as Set

main = do
    n <- getLine
    w <- getLine
    putStrLn $ main' n w

main' n ws =
    let
        w = sort $ map read $ words ws
        s = sum w
        h = s `div` 2
    in
        if h * 2 == s && solve h [0] Set.empty w then "possible" else "impossible"
            

solve _ _ _ [] = False
solve s [] ls (x:xs) = solve s (Set.toList ls) Set.empty xs
solve s (t:ts) ls (x:xs)
    | y == s = True
    | y > s = solve s ts ls (x:xs)
    | y < s = solve s ts (Set.insert y ls) (x:xs)
    where
        y = x + t
0