結果

問題 No.3757 Happy End
コンテスト
ユーザー norioc
提出日時 2026-10-15 21:23:29
言語 Haskell
(9.14.1 + ACL)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 52 ms / 2,000 ms
+ 393µs
コード長 1,091 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,991 ms
コンパイル使用メモリ 201,088 KB
実行使用メモリ 27,392 KB
最終ジャッジ日時 2026-10-15 21:23:46
合計ジャッジ時間 12,511 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
{-# OPTIONS_GHC -Wno-missing-signatures #-}

import Control.Monad
import Control.Monad.State.Strict
import Control.Applicative
import Data.Bool
import Data.Function
import Data.List
import Data.Ord
import Data.List.Split
-- import System.IO (hFlush, stdout)
import Debug.Trace

input = getLine :: IO String
ii = readLn :: IO Int
li = map read . words <$> getLine :: IO [Int]
printYn b = putStrLn $ bool "No" "Yes" b

pairwise :: [a] -> [(a, a)]
pairwise xs = zip xs (drop 1 xs)

windows :: Int -> [a] -> [[a]]
windows size xs
  | length w < size = []
  | otherwise = w : windows size (drop 1 xs)
  where
    w = take size xs

countIf f = length . filter f

minmax (x:xs)
  = foldl' (\(mi, ma) x -> (min mi x, max ma x)) (x, x) xs

solve ('H':'A':'P':'P':'Y':cs) = 1 + solve cs
solve (_:cs) = solve cs
solve [] = 0

main :: IO ()
main = do
  n <- ii
  s <- input
  let (a, b) = splitAt (n-5) s
  let ans = (solve a) + diff b "HAPPY"
  print ans
  where
    diff xs ys = countIf (\(x, y) -> x /= y) $ zip xs ys
0