結果

問題 No.602 隠されていたゲーム2
ユーザー pekempeypekempey
提出日時 2017-12-02 01:23:54
言語 Haskell
(9.8.2)
結果
AC  
実行時間 554 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 3,458 ms
コンパイル使用メモリ 160,640 KB
実行使用メモリ 56,480 KB
最終ジャッジ日時 2023-08-22 05:35:18
合計ジャッジ時間 7,134 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,136 KB
testcase_01 AC 3 ms
7,120 KB
testcase_02 AC 3 ms
7,256 KB
testcase_03 AC 3 ms
7,272 KB
testcase_04 AC 3 ms
7,272 KB
testcase_05 AC 3 ms
7,148 KB
testcase_06 AC 3 ms
7,080 KB
testcase_07 AC 3 ms
7,096 KB
testcase_08 AC 3 ms
7,296 KB
testcase_09 AC 2 ms
7,140 KB
testcase_10 AC 3 ms
7,296 KB
testcase_11 AC 3 ms
7,200 KB
testcase_12 AC 3 ms
7,184 KB
testcase_13 AC 3 ms
7,216 KB
testcase_14 AC 2 ms
7,156 KB
testcase_15 AC 2 ms
7,228 KB
testcase_16 AC 62 ms
17,004 KB
testcase_17 AC 133 ms
23,664 KB
testcase_18 AC 403 ms
40,248 KB
testcase_19 AC 554 ms
54,472 KB
testcase_20 AC 262 ms
37,908 KB
testcase_21 AC 232 ms
38,024 KB
testcase_22 AC 383 ms
54,356 KB
testcase_23 AC 373 ms
56,480 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/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 - v) <= oddMax)
      | otherwise = (evenMax, v, ans || abs (dist - v) <= evenMax)

0