結果

問題 No.90 品物の並び替え
ユーザー Hirotaka OhkuboHirotaka Ohkubo
提出日時 2016-07-28 15:17:34
言語 Haskell
(9.8.2)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 562 bytes
コンパイル時間 5,915 ms
コンパイル使用メモリ 171,520 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-24 10:32:39
合計ジャッジ時間 6,710 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 21 ms
8,960 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 6 ms
7,936 KB
testcase_04 AC 6 ms
7,936 KB
testcase_05 AC 21 ms
9,088 KB
testcase_06 AC 21 ms
8,960 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 152 ms
9,600 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

import Data.Array
import Data.List
import Control.Monad

main = do
  li <- getLine
  let (n:m:_) = map read $ words li
  cs <- forM [1..m] $ \_ -> do
    li <- getLine
    let (i1:i2:s:_) = map read $ words li
    return ((seq i1 i1,seq i2 i2),seq s s)
  print $ compute n cs

compute :: Int -> [((Int,Int),Int)] -> Int
compute n cs = maximum $ step [0..n-1] where
  ar = accumArray (+) 0 ((0,0),(n-1,n-1)) cs
  step [] = [ 0 ]
  step xs =
   [ s0 + s1
   | x <- xs
   , let xs1 = delete x xs
   , let s0 = sum [ ar ! (x,y) | y <- xs1 ]
   , s1 <- step xs1
   ]
0