4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AtCoder Beginner Contest 345 振り返り

Posted at

前回のAtCoderの振り返りです。

今回の結果

A,B 2完でした。

スクリーンショット 2024-03-19 1.45.09.png
スクリーンショット 2024-03-19 1.46.09.png

各問題の振り返り

A - Leftrightarrow

先頭と末尾をそれぞれ判定し、残りはallで判定しました。

main :: IO ()
main = do
  s <- getLine

  putStrLn if head s == '<' && last s == '>' && all (== '=') ((tail . init) s) then "Yes" else "No"

readInputInts :: IO [Int]
readInputInts = L.unfoldr (BC.readInt . BC.dropWhile C.isSpace) <$> BC.getLine

B - Integer Division Returns

そのまま解きました。値が0以上の時は+1しますが、そうでないときはそのままです。

main :: IO ()
main = do
  n <- readLn @Int

  let m = n `mod` 10
  let d = n `div` 10

  print $ if m > 0 then d + 1 else d

C - One Time Swap

WAになった解答はこちらです。

組み合わせ問題で、全体から2つ取って並び替える組み合わせ - 重複した文字列から2つ取って並び替える組み合わせ で解けます。

ただ、重複した文字列内で入れ替える場合があるので、重複した文字列が存在する場合は結果に+1する必要があります。

main :: IO ()
main = do
  s <- getLine

  let n = length s
  let r = length (LU.nubOrd s)

  let res = nc2 n - sum [nc2 (length xs) | xs <- L.group $ L.sort s, length xs >= 2]

  print $ if n == r then res else res + 1

nc2 :: Int -> Int
nc2 n = n * (n - 1) `div` 2

全体を振り返って

またぼちぼちがんばります!

4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?