結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
3405691582
|
| 提出日時 | 2017-03-21 09:11:29 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 736 bytes |
| コンパイル時間 | 11,022 ms |
| コンパイル使用メモリ | 173,440 KB |
| 実行使用メモリ | 30,924 KB |
| 最終ジャッジ日時 | 2024-07-05 05:28:01 |
| 合計ジャッジ時間 | 12,707 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 17 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Data.Array
import Data.Maybe (fromJust)
main = do
n <- read <$> getLine
ws <- map read . words <$> getLine
let
sumOfWs = sum ws
table = listArray ((1,1),(n,div sumOfWs 2)) $ repeat Nothing
putStrLn $ if even sumOfWs && snd (partition table n (div sumOfWs 2) ws) then "possible" else "impossible"
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 table!(n,m) of
Just b -> (table,b)
Nothing -> (table2//[((n,m),Just result)],result)
where
(table1,r1) = partition table (n-1) m ws
(table2,r2) = partition table1 (n-1) (m-w) ws
result = r1 || r2
3405691582