結果

問題 No.161 制限ジャンケン
ユーザー ducktailducktail
提出日時 2018-07-27 14:52:50
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 802 bytes
コンパイル時間 5,513 ms
コンパイル使用メモリ 164,892 KB
実行使用メモリ 7,224 KB
最終ジャッジ日時 2023-09-13 18:53:04
合計ジャッジ時間 5,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,108 KB
testcase_01 AC 2 ms
7,020 KB
testcase_02 AC 2 ms
6,952 KB
testcase_03 AC 2 ms
6,976 KB
testcase_04 AC 2 ms
7,020 KB
testcase_05 AC 2 ms
7,116 KB
testcase_06 AC 2 ms
7,224 KB
testcase_07 AC 2 ms
7,148 KB
testcase_08 AC 2 ms
7,132 KB
testcase_09 AC 2 ms
7,192 KB
testcase_10 AC 3 ms
7,148 KB
testcase_11 AC 2 ms
7,176 KB
testcase_12 AC 2 ms
7,092 KB
testcase_13 AC 2 ms
7,128 KB
testcase_14 AC 3 ms
7,096 KB
testcase_15 AC 2 ms
7,100 KB
testcase_16 AC 2 ms
7,116 KB
testcase_17 AC 2 ms
7,092 KB
testcase_18 AC 2 ms
7,148 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 Control.Applicative ((<$>))
import Data.List (foldl')

main :: IO ()
main = do
  [g, c, p] <- map read <$> words <$> getLine
  solve (g, c, p) <$> foldl' f (0, 0, 0) <$> getLine >>= print
  where f (g, c, p) s | s == 'G' = (g+1, c, p)
                      | s == 'C' = (g, c+1, p)
                      | otherwise = (g, c, p+1)

solve :: (Int,Int,Int) -> (Int,Int,Int) -> Int
solve (g, c, p) (g', c', p') = h $ f (g, c, p) (g', c', p')
  where f (g1, c1, p1) (g2, c2, p2) = let mg = min g1 c2
                                          mc = min c1 p2
                                          mp = min p1 g2
                                      in ((g1-mg, c1-mc, p1-mp), (g2-mp, c2-mg, p2-mc), 3 * (mg+mc+mp))
        h ((g1, c1, p1), (g2, c2, p2), p) = p + min g1 g2 + min c1 c2 + min p1 p2
0