結果

問題 No.550 夏休みの思い出(1)
ユーザー tottoripaper
提出日時 2017-07-28 23:26:28
言語 Haskell
(9.10.1)
結果
RE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 169,216 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-10 05:05:16
合計ジャッジ時間 3,674 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 RE * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List (sort)

readMany :: (Read a) => IO [a]
readMany = fmap (map read . words) getLine

solve :: (Integer -> Integer) -> Integer -> Integer -> Integer
solve f l r
  | l == r = 10^9
  | abs (r - l) == 1 = l
  | f mid > 0 = solve f l mid
  | otherwise = solve f mid r
  where
    mid = (l + r) `div` 2

isValid f x = f x == 0

main = do
  [a, b, c] <- readMany
  let x0 = solve f (-10^9) (10^9)
      x1 = solve f (-10^9) x0
      x2 = solve f (x0 + 1) (10^9)
      f x = x^3 + a * x^2 + b * x + c
      l = sort $ case (isValid f x1, isValid f x2, x1 /= x2) of
        (True, True, True) -> [x0, x1, x2]
        (True, False, _) -> let [x0', x1'] = sort [x0, x1]
                                x2' = solve f (x1' - 1) x0'
                                x3' = solve f (-10^9) x0'
                            in [x0', x1', if isValid f x2' then x2' else x3']
        (False, True, _) -> let [x0', x1'] = sort [x0, x2]
                                x2' = solve f (x1' - 1) x0'
                                x3' = solve f (x1' + 1) (10^9)
                            in [x0', x1', if isValid f x2' then x2' else x3']
        otherwise -> undefined
  -- print [x0, x1, x2]
  putStrLn $ unwords $ map show l
0