結果

問題 No.602 隠されていたゲーム2
ユーザー pekempeypekempey
提出日時 2017-12-02 01:21:35
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 673 bytes
コンパイル時間 8,531 ms
コンパイル使用メモリ 173,696 KB
実行使用メモリ 53,760 KB
最終ジャッジ日時 2024-05-06 00:32:44
合計ジャッジ時間 11,426 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 99 ms
20,992 KB
testcase_18 AC 322 ms
37,504 KB
testcase_19 AC 436 ms
51,840 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 313 ms
51,712 KB
testcase_23 AC 299 ms
53,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

main = do
  _ <- getLine
  d <- map read . words <$> getLine
  [x, y] <- map read . words <$> getLine
  print $ solve d x y

solve :: [Int] -> Int -> Int -> Int
solve d x y
  | x == 0 && y == 0 = 0
  | dist `elem` d    = 1 
  | f                = 2
  | otherwise        = -1
  where
    dist = abs x + abs y
    f = if even dist
          then dist <= 2 * maximum d
          else let (_, _, ans) = foldl' g (0, 0, False) (sort d) in ans
    g :: (Int, Int, Bool) -> Int -> (Int, Int, Bool)
    g (evenMax, oddMax, ans) v
      | even v    = (v, oddMax, ans || abs (dist - x) <= evenMax)
      | otherwise = (evenMax, v, ans || abs (dist - x) <= oddMax)

0