結果

問題 No.161 制限ジャンケン
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-07-23 00:19:58
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,204 bytes
コンパイル時間 3,297 ms
コンパイル使用メモリ 161,064 KB
実行使用メモリ 7,572 KB
最終ジャッジ日時 2023-08-20 05:09:29
合計ジャッジ時間 4,522 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,516 KB
testcase_01 AC 2 ms
7,440 KB
testcase_02 AC 3 ms
7,372 KB
testcase_03 AC 3 ms
7,572 KB
testcase_04 AC 2 ms
7,388 KB
testcase_05 AC 3 ms
7,372 KB
testcase_06 AC 3 ms
7,456 KB
testcase_07 AC 2 ms
7,392 KB
testcase_08 AC 2 ms
7,492 KB
testcase_09 AC 3 ms
7,452 KB
testcase_10 AC 3 ms
7,516 KB
testcase_11 AC 3 ms
7,456 KB
testcase_12 AC 3 ms
7,472 KB
testcase_13 AC 3 ms
7,552 KB
testcase_14 AC 3 ms
7,436 KB
testcase_15 AC 3 ms
7,436 KB
testcase_16 AC 3 ms
7,456 KB
testcase_17 AC 2 ms
7,476 KB
testcase_18 AC 3 ms
7,436 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

ソースコード

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