結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー aimy
提出日時 2017-04-30 11:07:18
言語 Haskell
(9.10.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 781 bytes
コンパイル時間 7,108 ms
コンパイル使用メモリ 171,904 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-24 11:59:02
合計ジャッジ時間 8,322 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:13:48: 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."
   |
13 |   chead = maximum $ (0:) $ map length $ filter head $ group $ replicate d True ++ dropWhile not cs
   |                                                ^^^^

Main.hs:14:48: 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."
   |
14 |   clast = maximum $ (0:) $ map length $ filter head $ group $ (reverse . dropWhile not . reverse) cs ++ replicate d True
   |                                                ^^^^

Main.hs:21:50: 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."
   |
21 |    return $ maximum $ (0:) $ map length $ filter head $ group cs'
   |                                                  ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Char
import Data.List
import Control.Monad

main = do
 d <- readLn
 cs <- map (\c -> if c=='o' then True else False) . filter isAlpha <$> getContents
 print (gw2 d cs)

gw2 :: Int -> [Bool] -> Int
gw2 d cs = maximum [chead, clast, maximum (0:cinter)]
 where
  chead = maximum $ (0:) $ map length $ filter head $ group $ replicate d True ++ dropWhile not cs
  clast = maximum $ (0:) $ map length $ filter head $ group $ (reverse . dropWhile not . reverse) cs ++ replicate d True
  cinter = do
   i <- [0 .. 14-d]
   m <- [1..d]
   let pat = replicate i False ++ replicate m True ++ replicate (14-(m+i)) False
   let cs' = zipWith (||) pat cs
   guard (length (filter id cs') == length (filter id cs) + m)
   return $ maximum $ (0:) $ map length $ filter head $ group cs'
0