結果
| 問題 |
No.161 制限ジャンケン
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-05-27 18:02:13 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,315 bytes |
| コンパイル時間 | 232 ms |
| コンパイル使用メモリ | 155,264 KB |
| 最終ジャッジ日時 | 2024-11-14 19:44:55 |
| 合計ジャッジ時間 | 610 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、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:3:1: error: [GHC-87110]
Could not load module ‘Data.Hashable’.
It is a member of the hidden package ‘hashable-1.4.3.0’.
Use -v to see a list of the files searched for.
|
3 | import Data.Hashable (Hashable)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Main.hs:4:1: error: [GHC-61948]
Could not find module ‘Data.HashMap.Strict’.
Perhaps you meant
Data.Map.Strict (needs flag -package-id containers-0.6.8)
Data.IntMap.Strict (needs flag -package-id containers-0.6.8)
Use -v to see a list of the files searched for.
|
4 | import qualified Data.HashMap.Strict as HS
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
import Control.Applicative ((<$>))
import qualified Data.ByteString.Char8 as C
import Data.Hashable (Hashable)
import qualified Data.HashMap.Strict as HS
import Data.Maybe (fromJust)
type Count = Int
type Counter a = HS.HashMap a Count
addElement :: (Hashable a, Eq a) => a -> Counter a -> Counter a
addElement x = HS.insertWith (+) x 1
buildCharCounter :: C.ByteString -> Counter Char
buildCharCounter = C.foldr addElement HS.empty
countElement :: (Hashable a, Eq a) => Counter a -> a -> Count
countElement = flip $ HS.lookupDefault 0
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 = countElement ctr 'G'
cZ0 = countElement ctr 'C'
pZ0 = countElement 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
はむ吉🐹