結果

問題 No.161 制限ジャンケン
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-07-23 00:19:58
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,204 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 147,968 KB
最終ジャッジ日時 2024-05-07 12:31:23
合計ジャッジ時間 2,539 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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:2:1: error: [GHC-87110]
    Could not load module ‘Data.Map.Strict’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
2 | import qualified Data.Map.Strict as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import qualified Data.ByteString.Char8 as C
import qualified Data.Map.Strict as M
import Data.Maybe (fromJust)

type Count = Int
type Counter a = M.Map a Count

addElement :: Ord a => a -> Counter a -> Counter a
addElement x = M.insertWith (+) x 1

buildCharCounter :: C.ByteString -> Counter Char
buildCharCounter = C.foldr addElement M.empty

countElem :: Ord a => Counter a -> a -> Count
countElem ctr el = M.findWithDefault 0 el ctr

unsafeReadInt :: C.ByteString -> Int
unsafeReadInt = fst . fromJust . C.readInt

calcScore :: Int -> Int -> Int -> Counter Char -> Int
calcScore g0 c0 p0 ctr = 3 * (gWin + cWin + pWin) + gDraw + cDraw + pDraw
    where
        gZ0 = countElem ctr 'G'
        cZ0 = countElem ctr 'C'
        pZ0 = countElem ctr 'P'
        gWin = min g0 cZ0
        cWin = min c0 pZ0
        pWin = min p0 gZ0
        gZ = gZ0 - pWin
        cZ = cZ0 - gWin
        pZ = pZ0 - cWin
        g = g0 - gWin
        c = c0 - cWin
        p = p0 - pWin
        gDraw = min g gZ
        cDraw = min c cZ
        pDraw = min p pZ


main :: IO ()
main = do
    [g, c, p] <- fmap unsafeReadInt . C.words <$> C.getLine
    ctr <- buildCharCounter <$> C.getLine
    print $ calcScore g c p ctr
0