前回のAtCoderの振り返りです。
今回の結果
A,B 2完でした。
各問題の振り返り
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
全体を振り返って
またぼちぼちがんばります!