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でABC452を解く

1
Posted at

はじめに

今回はCまで。Dは尺取り法で解けそうでしたが解説ではDPのようで方針間違ってしまいました。

A問題

該当する日に当たるかチェックします。

A問題提出

main = do
  [m,d] <- readInts
  let day = (m,d)
  let dicts = zip [1,3,5,7,9] [7,3,5,7,9]
  putStrLn $ bool "No" "Yes" (day `elem` dicts)

B問題

縁の場合は'#'で内側は'.'にします。

B問題提出

main = do
  [h,w] <- readInts
  let grid = [[ sharpOrDot i j h w | j <- [1..w] ] | i <- [1..h]]
  putStr $ unlines grid

sharpOrDot i j w h
  | i == 1 || i == w = '#'
  | j == 1 || j == h = '#'
  | otherwise = '.'

C問題

最初はStringでやろうとしてTLEでした。Arrayを使って、Setを使って無事ACできました。

C問題提出

main = do
  n <- readLn :: IO Int
  abs <- replicateM n $ do
    [a,b] <- readInts
    return (a,b)
  m <- readLn :: IO Int
  ss <- replicateM m BS.getLine
  let arrS = A.accumArray (flip (:)) [] (1,10) $ map (\s -> (BS.length s,s) ) ss :: A.Array Int [BS.ByteString]
  let arrBones = A.listArray (1,n) $ [ S.fromList $ map (\s -> BS.index s (b-1)) $ arrS A.! a | (a,b) <- abs ] :: A.Array Int (S.Set Char)
  putStr $ unlines $ map (bool "No" "Yes") $ solve n arrBones ss

solve _n _arrBones [] = []
solve n arrBones (s:ss)
  | BS.length s /= n = False : solve n arrBones ss
  | otherwise = ans : solve n arrBones ss
  where
    ans = and $ zipWith S.member (BS.unpack s) (A.elems arrBones)

おわりに

C問題なんとか粘って間に合いました。

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?