結果

問題 No.116 門松列(1)
ユーザー tjnt
提出日時 2021-10-08 15:55:08
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 434 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 172,032 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 03:22:21
合計ジャッジ時間 2,655 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

solve :: [Int] -> Int
solve xs
  | length xs >= 3 = (if judge (take 3 xs) then 1 else 0)
                   + solve (drop 1 xs)
  | otherwise = 0
  where
    judge :: [Int] -> Bool
    judge xs@[a1,a2,a3] =
        (maximum xs == a2 || minimum xs == a2)
        && a1 /= a3 && a1 /= a2 && a2 /= a3
    judge _ = undefined

main :: IO ()
main = do
    _ <- getLine
    a <- map read . words <$> getLine :: IO [Int]
    print $ solve a
0