結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー aimy
提出日時 2018-02-03 10:50:18
言語 Haskell
(9.10.1)
結果
WA  
実行時間 -
コード長 735 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 174,208 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-11 15:19:06
合計ジャッジ時間 2,538 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:8:28: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
  |
8 |     ans = case (length gs, head cs) of
  |                            ^^^^

Main.hs:12:27: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
12 |       (2, 'x') -> min 14 (head gs + d)
   |                           ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List

main = do
  d <- readLn
  cs <- concat . words <$> getContents
  let
    gs = (map length . group) cs
    ans = case (length gs, head cs) of
      (1, 'o') -> 14
      (1, 'x') -> d
      (2, 'o') -> min 14 (last gs + d)
      (2, 'x') -> min 14 (head gs + d)
      (3, 'o') -> let [x,y,z] = gs in if d>=y then x+y+z else max x z + d
      (3, 'x') -> let [x,y,z] = gs in max (y + min x d) (y + min z d)
      (_, 'o') -> maximum (iFilter even (zipWith3 (\x y z -> if d>=y then x+y+z else max x z + d) gs (drop 1 gs) (drop 2 gs)))
      (_, 'x') -> maximum (iFilter odd (zipWith3 (\x y z -> if d>=y then x+y+z else max x z + d) gs (drop 1 gs) (drop 2 gs)))
  print ans

iFilter p xs = [x | (i,x) <- zip [0..] xs, p i]
0