結果

問題 No.406 鴨等間隔の法則
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-03 23:23:28
言語 Haskell
(9.8.2)
結果
AC  
実行時間 522 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 9,184 ms
コンパイル使用メモリ 167,856 KB
実行使用メモリ 47,924 KB
最終ジャッジ日時 2023-09-21 17:38:37
合計ジャッジ時間 17,485 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
26,400 KB
testcase_01 AC 3 ms
7,748 KB
testcase_02 AC 2 ms
7,780 KB
testcase_03 AC 3 ms
7,816 KB
testcase_04 AC 423 ms
41,480 KB
testcase_05 AC 143 ms
24,228 KB
testcase_06 AC 152 ms
24,456 KB
testcase_07 AC 153 ms
24,540 KB
testcase_08 AC 422 ms
40,728 KB
testcase_09 AC 492 ms
45,912 KB
testcase_10 AC 183 ms
26,376 KB
testcase_11 AC 362 ms
40,520 KB
testcase_12 AC 252 ms
35,120 KB
testcase_13 AC 223 ms
33,036 KB
testcase_14 AC 373 ms
40,776 KB
testcase_15 AC 22 ms
14,028 KB
testcase_16 AC 43 ms
15,304 KB
testcase_17 AC 22 ms
13,232 KB
testcase_18 AC 32 ms
15,064 KB
testcase_19 AC 42 ms
15,844 KB
testcase_20 AC 52 ms
17,296 KB
testcase_21 AC 62 ms
17,148 KB
testcase_22 AC 92 ms
21,444 KB
testcase_23 AC 263 ms
36,136 KB
testcase_24 AC 331 ms
39,212 KB
testcase_25 AC 522 ms
46,820 KB
testcase_26 AC 493 ms
47,848 KB
testcase_27 AC 312 ms
45,804 KB
testcase_28 AC 312 ms
44,808 KB
testcase_29 AC 482 ms
47,924 KB
testcase_30 AC 483 ms
45,856 KB
testcase_31 AC 462 ms
41,928 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 Control.Applicative ((<$>))
import qualified Data.IntSet as S
import Data.List (sort)

-- 与えられた数列の階差数列を求める関数
-- WriterによるPython解と同様の考え方による
diff :: Num a => [a] -> [a]
diff xs = zipWith (-) (tail xs) (init xs)

-- 与えられた数列が二条件を同時に満たすかを判定する関数
isKamo :: [S.Key] -> Bool
isKamo = f . S.fromList . diff . sort
    where f s = S.size s == 1 && S.notMember 0 s

main :: IO ()
main = do
    -- Nは使わないので読み捨てる
    _ <- getLine
    xs <- fmap read . words <$> getLine :: IO [Int]
    putStrLn $ if isKamo xs then "YES" else "NO"
0