結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-03 18:58:53
言語 Haskell
(9.8.2)
結果
AC  
実行時間 804 ms / 2,000 ms
コード長 731 bytes
コンパイル時間 5,440 ms
コンパイル使用メモリ 161,516 KB
実行使用メモリ 111,064 KB
最終ジャッジ日時 2023-09-21 03:33:04
合計ジャッジ時間 19,351 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,972 KB
testcase_01 AC 3 ms
7,148 KB
testcase_02 AC 3 ms
7,036 KB
testcase_03 AC 3 ms
7,052 KB
testcase_04 AC 3 ms
7,192 KB
testcase_05 AC 3 ms
7,200 KB
testcase_06 AC 2 ms
7,168 KB
testcase_07 AC 3 ms
7,208 KB
testcase_08 AC 3 ms
7,492 KB
testcase_09 AC 3 ms
7,216 KB
testcase_10 AC 3 ms
7,348 KB
testcase_11 AC 3 ms
7,352 KB
testcase_12 AC 3 ms
7,272 KB
testcase_13 AC 3 ms
7,296 KB
testcase_14 AC 262 ms
52,468 KB
testcase_15 AC 784 ms
110,964 KB
testcase_16 AC 263 ms
55,276 KB
testcase_17 AC 6 ms
11,260 KB
testcase_18 AC 323 ms
58,680 KB
testcase_19 AC 434 ms
80,144 KB
testcase_20 AC 654 ms
108,752 KB
testcase_21 AC 472 ms
71,660 KB
testcase_22 AC 112 ms
29,808 KB
testcase_23 AC 675 ms
105,612 KB
testcase_24 AC 152 ms
31,972 KB
testcase_25 AC 343 ms
68,384 KB
testcase_26 AC 614 ms
104,120 KB
testcase_27 AC 482 ms
89,312 KB
testcase_28 AC 495 ms
86,212 KB
testcase_29 AC 804 ms
111,064 KB
testcase_30 AC 22 ms
13,548 KB
testcase_31 AC 12 ms
11,732 KB
testcase_32 AC 402 ms
62,408 KB
testcase_33 AC 343 ms
59,384 KB
testcase_34 AC 262 ms
50,472 KB
testcase_35 AC 631 ms
96,416 KB
testcase_36 AC 22 ms
14,264 KB
testcase_37 AC 434 ms
75,056 KB
testcase_38 AC 342 ms
59,188 KB
testcase_39 AC 122 ms
26,876 KB
testcase_40 AC 654 ms
104,624 KB
testcase_41 AC 192 ms
35,244 KB
testcase_42 AC 563 ms
101,688 KB
testcase_43 AC 283 ms
55,620 KB
testcase_44 AC 512 ms
92,424 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 Control.Monad (replicateM)

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
    n <- readLn
    cs <- map (tuplify2 .
        map read . words) <$> replicateM n getLine
    print $ solve p q cs
0