結果

問題 No.358 も~っと!門松列
ユーザー aimy
提出日時 2017-07-13 11:36:20
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 564 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 168,064 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-07 18:06:35
合計ジャッジ時間 2,141 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
 [a1,a2,a3] <- map read . words <$> getLine
 putStrLn $ maybe "INF" show (kadomatsu a1 a2 a3)

kadomatsu a1 a2 a3
 | isKadomatsu a1 a2 a3 = Nothing
 | not (isDistinct a1 a2 a3) = Just 0
 | otherwise = Just $ length $ filter (\p -> isKadomatsu (mod a1 p) (mod a2 p) (mod a3 p)) [3..amax]
 where amax = maximum [a1,a2,a3]

isKadomatsu a1 a2 a3 = isDistinct a1 a2 a3 && not (isSorted a1 a2 a3)

isDistinct a1 a2 a3 = a1/=a2 && a2/=a3 && a3/=a1

isSorted a1 a2 a3 = [a1,a2,a3] == sort [a1,a2,a3] || [a1,a2,a3] == (reverse . sort) [a1,a2,a3]
0