結果

問題 No.91 赤、緑、青の石
コンテスト
ユーザー ducktail
提出日時 2018-05-11 16:05:52
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
+ 174µs
コード長 589 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 818 ms
コンパイル使用メモリ 196,992 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2026-07-19 04:53:47
合計ジャッジ時間 2,653 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

import Control.Applicative ((<$>))
import Data.List (sort)

main :: IO ()
main = solve <$> map read <$> words <$> getLine >>= print

solve :: [Int] -> Int
solve xs = bsearch (judge (a, b, c)) a c
  where [a, b, c] = sort xs

bsearch :: (Int -> Bool) -> Int -> Int -> Int
bsearch f o n | n - o <= 1 = o
              | f m = bsearch f m n
              | otherwise = bsearch f o m
  where m = (o + n) `div` 2

judge :: (Int, Int, Int) -> Int -> Bool
judge (a, b, c) m = (m > b && 2*m - a - b <= (c - m) `div` 2) ||
                    (m <= b && m - a <= (b - m) `div` 2 + (c - m) `div` 2)
0