結果

問題 No.90 品物の並び替え
ユーザー くれちーくれちー
提出日時 2017-04-15 11:22:11
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 744 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 147,840 KB
最終ジャッジ日時 2024-04-27 02:25:16
合計ジャッジ時間 498 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:20:31: error: [GHC-58481]
    parse error on input ‘<-’
    Suggested fix: Possibly caused by a missing 'do'?
   |
20 |         [item1, item2, score] <- map read . words <$> table
   |                               ^^

ソースコード

diff #

import Control.Monad (replicateM)
import Data.List (elemIndex, permutations)

solve :: Integral a => a -> [(a, a, a)] -> a
solve n table = maximum $ do
    items <- permutations [0..n - 1]
    return $ calc items table where
        calc :: Integral a => [a] -> [(a, a, a)] -> a
        calc items' table' = sum $ do
            (item1, item2, score) <- table'
            return $ case (compare <$> elemIndex item1 <*> elemIndex item2) items' of
                LT -> score
                GT -> 0

main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine
    table <- replicateM m getLine
    let table' = do
        [item1, item2, score] <- map read . words <$> table
        return (item1, item2, score)
    print $ solve n table'
0