結果
問題 | No.4 おもりと天秤 |
ユーザー | 3405691582 |
提出日時 | 2017-03-21 09:32:54 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 142 ms / 5,000 ms |
コード長 | 818 bytes |
コンパイル時間 | 4,599 ms |
コンパイル使用メモリ | 163,772 KB |
実行使用メモリ | 27,928 KB |
最終ジャッジ日時 | 2023-09-08 17:20:43 |
合計ジャッジ時間 | 6,617 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,276 KB |
testcase_01 | AC | 2 ms
7,292 KB |
testcase_02 | AC | 4 ms
8,636 KB |
testcase_03 | AC | 3 ms
7,572 KB |
testcase_04 | AC | 3 ms
7,724 KB |
testcase_05 | AC | 93 ms
20,424 KB |
testcase_06 | AC | 3 ms
7,260 KB |
testcase_07 | AC | 112 ms
20,744 KB |
testcase_08 | AC | 3 ms
7,592 KB |
testcase_09 | AC | 4 ms
8,988 KB |
testcase_10 | AC | 112 ms
22,804 KB |
testcase_11 | AC | 3 ms
7,400 KB |
testcase_12 | AC | 3 ms
7,388 KB |
testcase_13 | AC | 2 ms
7,340 KB |
testcase_14 | AC | 3 ms
7,276 KB |
testcase_15 | AC | 2 ms
7,364 KB |
testcase_16 | AC | 3 ms
7,368 KB |
testcase_17 | AC | 2 ms
7,236 KB |
testcase_18 | AC | 142 ms
27,928 KB |
testcase_19 | AC | 82 ms
17,732 KB |
testcase_20 | AC | 82 ms
20,252 KB |
testcase_21 | AC | 73 ms
17,672 KB |
testcase_22 | AC | 82 ms
17,708 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
ソースコード
import Prelude hiding (lookup) import Data.Map hiding (map,partition) import Data.Maybe (fromJust) type Table = Map (Int,Int) Bool main = do n <- read <$> getLine ws <- map read . words <$> getLine let sumOfWs = sum ws putStrLn $ if even sumOfWs && snd (partition empty (n,div sumOfWs 2) ws) then "possible" else "impossible" partition :: Table -> (Int,Int) -> [Int] -> (Table,Bool) partition table (n,m) [] | m == 0 = (table,True) | otherwise = (table,False) partition table (n,m) (w:ws) | m < 0 = (table,False) | m == 0 = (table,True) | otherwise = case lookup (n,m) table of Just b -> (table,b) Nothing -> (insert (n,m) result table2,result) where (table1,r1) = partition table (n-1,m) ws (table2,r2) = partition table1 (n-1,m-w) ws result = r1 || r2