結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-06 22:40:59
言語 Haskell
(9.8.2)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 859 bytes
コンパイル時間 4,721 ms
コンパイル使用メモリ 165,596 KB
実行使用メモリ 12,260 KB
最終ジャッジ日時 2023-09-21 03:33:20
合計ジャッジ時間 4,854 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,492 KB
testcase_01 AC 3 ms
7,464 KB
testcase_02 AC 3 ms
7,384 KB
testcase_03 AC 3 ms
7,516 KB
testcase_04 AC 2 ms
7,704 KB
testcase_05 AC 3 ms
7,512 KB
testcase_06 AC 2 ms
7,416 KB
testcase_07 AC 3 ms
7,560 KB
testcase_08 AC 3 ms
7,596 KB
testcase_09 AC 3 ms
7,768 KB
testcase_10 AC 2 ms
7,672 KB
testcase_11 AC 3 ms
7,548 KB
testcase_12 AC 3 ms
7,640 KB
testcase_13 AC 3 ms
7,720 KB
testcase_14 AC 22 ms
12,040 KB
testcase_15 AC 43 ms
11,976 KB
testcase_16 AC 22 ms
11,952 KB
testcase_17 AC 3 ms
7,776 KB
testcase_18 AC 22 ms
12,128 KB
testcase_19 AC 22 ms
12,008 KB
testcase_20 AC 32 ms
11,928 KB
testcase_21 AC 32 ms
12,004 KB
testcase_22 AC 12 ms
12,120 KB
testcase_23 AC 32 ms
12,200 KB
testcase_24 AC 12 ms
12,076 KB
testcase_25 AC 22 ms
12,260 KB
testcase_26 AC 32 ms
12,180 KB
testcase_27 AC 32 ms
12,096 KB
testcase_28 AC 32 ms
12,084 KB
testcase_29 AC 42 ms
11,964 KB
testcase_30 AC 4 ms
9,432 KB
testcase_31 AC 4 ms
8,364 KB
testcase_32 AC 22 ms
11,996 KB
testcase_33 AC 23 ms
12,028 KB
testcase_34 AC 22 ms
12,144 KB
testcase_35 AC 32 ms
12,184 KB
testcase_36 AC 5 ms
9,840 KB
testcase_37 AC 22 ms
12,048 KB
testcase_38 AC 22 ms
12,196 KB
testcase_39 AC 12 ms
11,804 KB
testcase_40 AC 32 ms
12,172 KB
testcase_41 AC 22 ms
12,088 KB
testcase_42 AC 32 ms
12,152 KB
testcase_43 AC 22 ms
12,116 KB
testcase_44 AC 33 ms
12,020 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.ByteString.Lazy.Char8 as LC
import Data.Maybe (fromJust)

readInt :: LC.ByteString -> Int
readInt = fst . fromJust . LC.readInt

tuplify2 :: [a] -> (a, a)
tuplify2 [x, y] = (x, y)

generateJudge :: Integral a => a -> a -> ((a, a) -> Bool)
generateJudge 0 0 = \(x, y) -> x == 0 && y == 0
generateJudge p q
    | odd s0 = f
    | otherwise = \(x, y) -> f (x, y) && even (div x g + div y g)
    where
        g = gcd p q
        s0 = sum $ map (`div` g) [p, q]
        f (x, y) = mod x g == 0 && mod y g == 0

solve :: Integral a => a -> a -> [(a, a)] -> Int
solve p q = length . filter (generateJudge p q)

main :: IO ()
main = do
    [p, q] <- map read . words <$> getLine
    _ <- getLine
    cs <- map (tuplify2 .
        map readInt . LC.words) . LC.lines <$> LC.getContents
    print $ solve p q cs
0