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

1
Posted at

はじめに

今回はCまで解けました。
直前にUbuntu 26.04 にアップデートした関係でonline-judgeツールがうまく動かず手でコピペしながらやったのでいつもより若干もたつきました。
Dの解き方全く分からずEに行ってみましたができそうでできない感じです。

A問題

言われた通りに判定しました。

A問題提出

main = do
  [a,b,c] <- readInts
  putStrLn $ bool "No" "Yes" $ a /= b && b == c

B問題

すべての部分図形を作り180度図形を回転させて同じかどうかで判定します。
部分図形を作るとこでハマりかけたのでCを先にといて戻ってきて落ち着いてやったらうまく解けました。

B問題提出

main = do
  [h,w] <- readInts
  ss <- replicateM h getLine
  let cands = map f [[[ ss !! x !! y | x <- [i..k]] | y <- [j..l]] | i <- [0..h-1], j <- [0..w-1], k <- [i..h-1], l <- [j..w-1]]
  print $ length $ filter id cands

f ss = ss == (reverse $ map reverse ss)

C問題

同じ数字ごとの総数を作って大きい方から2つを削ったあとの合計値を求めます。
同じ数字が2種類以下の場合は例外として処理します。

C問題提出

main = do
  [_n,k] <- readInts
  as <- readInts
  let bs = sortBy (flip compare) $ map (\g -> (head g * length g)) $ group $ sort as
  if length bs <= k then
    print (0::Int)
  else do
    let cand = drop k bs
    print $ sum cand

おわりに

今回A->C->Bの順で解きました。
Dのデータ構造がまったく予想できずEに行ってみてなんとなく解けそうな感じでやってみましたが結局だめでした。

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?