1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

HaskellでABC462を解く

1
Posted at

はじめに

今回はCまで。DはIMOS法を使ってテストケースは通りましたがWAを払拭できずでした。

A問題

フィルターでアルファベット以外を集めます。

A問題提出

main = do
  s <- getLine
  let ans = filter (`notElem` ['a'..'z']) s
  putStrLn ans

B問題

関係の向きを逆にして集計しなおします。

B問題提出

main = do
  n <- readLn :: IO Int
  aas <- replicateM n $ do
    (_:as) <- readInts
    return as
  putStr $ unlines $ solve n aas

solve n aas =  map step3 cands
  where
    bbs = sort $ concatMap step $ zip [1..] aas
    arr = A.accumArray (flip (:)) [] (1,n) bbs :: A.Array Int [Int]
    cands = map (step2 arr) [1..n]

step (i,as) = bs
  where
    bs = map (,i) as

step2 arr i = arr A.! i

step3 xs
  | null xs = "0"
  | otherwise = show (length xs) ++ " " ++ unwords ( map show (sort xs))

C問題

Xを昇順でソートしておいて、Yの最小座標より小さいものがなければそれが求めたいものです。

C問題提出

main = do
  n <- readLn :: IO Int
  xys <- fmap sort <$> replicateM n $ do
    [x,y] <- readInts
    return (x,y)
  print $ snd $ solve $ map snd xys

solve :: [Int] -> (Int,Int)
solve = foldl step (maxBound::Int,0)
  where
    step (y0,cnt) y
      | y < y0 = (y,cnt+1)
      | otherwise = (y0,cnt)

おわりに

D問題の方針は気が付きましたが取りこぼしてしまいました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?