結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー aimy
提出日時 2018-02-03 12:03:03
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 654 bytes
コンパイル時間 1,335 ms
コンパイル使用メモリ 170,624 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-11 15:19:54
合計ジャッジ時間 2,418 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:14:90: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
14 |         ansi = map (\[x,y,z] -> if d>=y then x+y+z else max x z + d) <$> windows3 (init (tail gs))
   |                                                                                          ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List
import Control.Monad

main = do
  d <- readLn
  cs <- concat . words <$> getContents
  let
    gs = (map length . group) (replicate 14 'x' ++ cs ++ replicate 14 'x')
    ans = do
      guard (length gs > 2)
      let
        ansh = let (_:h:_) = gs in h + d
        anst = let (_:t:_) = reverse gs in t + d
        ansi = map (\[x,y,z] -> if d>=y then x+y+z else max x z + d) <$> windows3 (init (tail gs))
      pure (maximum [ansh, anst, maybe 0 maximum ansi])
  print (maybe d id ans)

windows3 xs
 | length xs < 3 = Nothing
 | otherwise = Just [g | (i,g) <- zip [0..] (zipWith3 (\x y z -> [x,y,z]) xs (drop 1 xs) (drop 2 xs)), even i]
0