結果

問題 No.4 おもりと天秤
ユーザー e7a894e7a894
提出日時 2018-05-18 23:03:25
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 613 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 158,492 KB
実行使用メモリ 7,724 KB
最終ジャッジ日時 2023-09-10 23:09:37
合計ジャッジ時間 3,034 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,116 KB
testcase_01 AC 3 ms
6,848 KB
testcase_02 AC 2 ms
7,072 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 3 ms
7,268 KB
testcase_09 AC 3 ms
7,592 KB
testcase_10 AC 3 ms
7,576 KB
testcase_11 AC 3 ms
6,968 KB
testcase_12 AC 2 ms
6,900 KB
testcase_13 AC 3 ms
6,960 KB
testcase_14 AC 2 ms
6,936 KB
testcase_15 AC 3 ms
7,064 KB
testcase_16 WA -
testcase_17 AC 3 ms
6,848 KB
testcase_18 AC 3 ms
7,664 KB
testcase_19 AC 3 ms
7,528 KB
testcase_20 AC 3 ms
7,676 KB
testcase_21 AC 3 ms
7,692 KB
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 #

import Data.List

main = do
  n <- readLn :: IO Int
  ws <- (map read . words) <$> getLine
  putStr $ if odd $ sum ws then "impossible" else resolve ws

resolve ws = resolve' (getPairs n' 0 ws)
  where
    n' = (sum ws) `div` 2
    resolve' :: [(Int, [Int])] -> String
    resolve' [] = "impossible"
    resolve' pairs@((a,bs):ps)
      | a == n' = "possible"
      | null bs = resolve' ps
      | otherwise = resolve' (getPairs n' a bs)

getPairs :: Int -> Int -> [Int] -> [(Int,[Int])]
getPairs e c (p:ps)
  | null ps = [(m, [])]
  | otherwise = (m, filter (<= (e - m)) ps):(getPairs e c ps)
    where m = c + p
0