結果

問題 No.358 も~っと!門松列
ユーザー alpha_virginisalpha_virginis
提出日時 2016-05-05 15:55:02
言語 Haskell
(9.8.2)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,299 bytes
コンパイル時間 6,765 ms
コンパイル使用メモリ 180,792 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 13:15:34
合計ジャッジ時間 7,667 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,944 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 )

Main.hs:22:5: warning: [GHC-53633] [-Woverlapping-patterns]
    Pattern match is redundant
    In an equation for ‘solve’: solve a b c | isKadomatsu a b c = ...
   |
22 |   | isKadomatsu a b c = -1
   |     ^^^^^^^^^^^^^^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.Array.IO

main :: IO ()
main = do
  ss <- C.getLine
  let (a, r1) = nextInt ss
  let (b, r2) = nextInt r1
  let (c, r3) = nextInt r2
  printans $ solve a b c

isKadomatsu :: Int -> Int -> Int -> Bool
isKadomatsu a b c
  | a < b && b > c && a /= c = True
  | a > b && b < c && a /= c = True
  | otherwise = False

solve :: Int -> Int -> Int -> Int
solve a b c
  | isKadomatsu a b c = -1
  | isKadomatsu a b c = -1
  | otherwise = solve2 a b c

solve2 :: Int -> Int -> Int -> Int
solve2 a b c = solve3 a b c m
  where m = max a $ max b c

solve3 :: Int -> Int -> Int -> Int -> Int
solve3 a b c m
  | m < 1 = 0
  | isKadomatsu a' b' c' = x + 1
  | otherwise = x
  where a' = mod a m
        b' = mod b m
        c' = mod c m
        x  = solve3 a b c (m - 1)

printans :: Int -> IO ()
printans n
  | n < 0     = putStrLn "INF"
  | otherwise = print n
  
nextInt :: C.ByteString -> (Int, C.ByteString)
nextInt ss
  | isDigit x = nextInt2 0 ss
  | otherwise = nextInt $ C.tail ss
  where x = C.head ss

nextInt2 :: Int -> C.ByteString -> (Int, C.ByteString)
nextInt2 n ss
  | C.null ss = (n, ss)
  | isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys
  | otherwise = (n, ys)
  where y  = C.head ss
        ys = C.tail ss
          
0