Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

ABC039をHaskellで

0
Posted at

A - 高橋直体

問題 ABC039A

シグネチャを決める。

abc039a :: Int -- A
        -> Int -- B
        -> Int -- C
        -> Int -- 答え
abc039a a b c = 2 * (a * b + b * c + c * a)

B - エージェント高橋君

問題 ABC039B

シグネチャを決める。

abc039b :: Int -- X
        -> Int -- 答え
abc039b x = head $ filter ((x ==) . (^ 4)) [1 ..]

C - ピアニスト高橋君

問題 ABC039C

シグネチャを決める。

abc039c :: String -- S
        -> String -- 答え

各位置から20文字眺めたらどうなるかを生成して、Sと比較する。

結果

import Data.List

abc039c :: String -> String
abc039c s = head
  [ ok
  | (ok, wb) <- zip oks (tails (cycle wbs))
  , isPrefixOf s wb ]
  where
    oks = ["Do","","Re","","Mi","Fa","","So","","La","","Si"]
    wbs = "WBWBWWBWBWBW"

D - 画像処理高橋君

問題 ABC039D

シグネチャを決める。

abc039d :: Int  -- H
        -> Int  -- W
        -> [String] -- Si
        -> [String] -- 答え

そもそも、AtCoder Tags にこの問題がセグメント木だと書いてあったので見てみたのだが、それらしくもなく解き方もわからない。
結局公式解説を読んで実装して、セグメント木との関連はまったく判らないまま。

結果

import Data.Array.Unboxed
import Data.Bool
import Data.List.Split

abc039d :: Int -> Int -> [String] -> [String]
abc039d h w css
  | concat css /= elems arr2 = ["impossible"]
  | otherwise = "possible" : chunksOf w (elems arr1)
  where
    bnds = ((1,1),(h,w))
    arr1, arr2 :: UArray (Int,Int) Char
-- 推定、白の8近傍は白、その他は黒
    arr1 = accumArray (flip const) '#' bnds
      [ (pq, '.')
      | (i,cs) <- zip [1 ..] css, (j,'.') <- zip [1 ..] cs
      , pq <- range ((pred i, pred j), (succ i, succ j))
      , inRange bnds pq]
-- 細線化、その位置または8近傍に黒があるなら黒、全く無ければ白
    arr2 = listArray bnds
      [ bool '#' '.' $ all (('.' ==) . (arr1 !)) $ filter (inRange bnds) $ range ((pred i, pred j), (succ i, succ j))
      | (i,j) <- range bnds ]
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?