結果

問題 No.4 おもりと天秤
ユーザー LeonardoneLeonardone
提出日時 2015-10-30 01:21:19
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 571 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 160,088 KB
実行使用メモリ 17,392 KB
最終ジャッジ日時 2023-10-11 05:27:59
合計ジャッジ時間 8,562 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 22 ms
10,360 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,888 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 3 ms
7,020 KB
testcase_12 AC 2 ms
6,948 KB
testcase_13 AC 2 ms
6,988 KB
testcase_14 AC 3 ms
6,960 KB
testcase_15 AC 3 ms
6,968 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Bits

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

main' n ws =
    let
        w = map read $ words ws
        s = foldl1 (+) w `div` 2
        a = zip [0..n-1] w
        x = shiftL (1::Int) n
    in
        solve s (x - 1) a

solve _ 0 _ = "impossible"
solve n x a =
    if n == p
        then "posssible"
        else solve n (x - 1) a
    where
        p = foldl (calc x) 0 a
        
calc x p (i,e) = p + if testBit x i then e else 0
0