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

Posted at

はじめに

今回はC問題解けそうで解けずこんがらがってしまいました。

A問題

x,yそれぞれで範囲判定をする。

main = do
  [p,q] <- readInts
  [x,y] <- readInts
  let ans = inRange (p,p+99) x && inRange (q,q+99) y
  putStrLn $ bool "No" "Yes" ans

A問題提出

B問題

sで使われている文字がTakahashiの辞書で全て出てくるかつAokiの辞書で全て出てくるわけではない
のように判断すれば良い。

main = do
  [n,m] <- readInts
  s <- S.fromList <$> getLine
  t <- S.fromList <$> getLine
  q <- readLn :: IO Int
  replicateM_ q $ do
    w <- getLine
    let x = all (`S.member` s) w
    let y = all (`S.member` t) w
    if x && not y then
      putStrLn "Takahashi"
    else if y && not x then
      putStrLn "Aoki"
    else
      putStrLn "Unknown"

B問題提出

C問題

解説を見て解きました。似た考え方はできてましたが詰めが甘くWAの連発でした。

main = do
  [n,k,x] <- readInts
  as <- sortBy (flip compare) <$> readInts
  let bs = drop (n-k) as
  let y = count x 0 bs
  if y == -1 then
    print y
  else
    print $ (n-k) + y

count :: Int -> Int -> [Int] -> Int
count x i [] = -1
count x i (a:as)
  | x1 <= 0 = i+1
  | otherwise = count x1 (i+1) as
  where
    x1 = x - a

C問題提出

おわりに

最近Cがなかなか解けず苦戦が続いてる。。。意識して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?