結果

問題 No.4 おもりと天秤
コンテスト
ユーザー Leonardone
提出日時 2015-11-01 05:07:09
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 621 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,733 ms
コンパイル使用メモリ 193,024 KB
実行使用メモリ 1,309,056 KB
最終ジャッジ日時 2026-04-04 03:54:07
合計ジャッジ時間 13,475 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 MLE * 2 -- * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

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

import Data.List

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

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

solve _ _ _ [] = False
solve s [] ls (x:xs) = solve s ls [] xs
solve s (t:ts) ls (x:xs)
    | y == s = True
    | y > s = solve s ts zs (x:xs)
    | y < s = solve s ts (y:zs) (x:xs)
    where
        y = x + t
        zs = (t:ls)
0