結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー freecss00freecss00
提出日時 2020-02-14 23:30:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 670 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 36,236 KB
最終ジャッジ日時 2023-08-10 02:44:09
合計ジャッジ時間 4,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,752 KB
testcase_01 AC 18 ms
8,568 KB
testcase_02 AC 19 ms
8,780 KB
testcase_03 AC 19 ms
8,628 KB
testcase_04 AC 18 ms
8,608 KB
testcase_05 AC 18 ms
8,716 KB
testcase_06 AC 18 ms
8,728 KB
testcase_07 AC 18 ms
8,572 KB
testcase_08 AC 17 ms
8,616 KB
testcase_09 AC 18 ms
8,712 KB
testcase_10 AC 115 ms
17,824 KB
testcase_11 AC 148 ms
19,240 KB
testcase_12 AC 660 ms
27,360 KB
testcase_13 AC 81 ms
15,984 KB
testcase_14 AC 217 ms
21,284 KB
testcase_15 AC 159 ms
14,136 KB
testcase_16 AC 177 ms
20,236 KB
testcase_17 AC 112 ms
13,696 KB
testcase_18 AC 670 ms
27,352 KB
testcase_19 AC 211 ms
17,240 KB
testcase_20 AC 286 ms
36,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import Counter

n, m, k = map(int, input().split())
line = input().split()
op = line[0]
B = list(map(int, line[1:]))
A = [int(input()) for _ in range(n)]

if op == '+':
    mod = [a % k for a in A]
    modcnt = Counter(mod)
    ans = sum([modcnt[(k - (b%k)) % k] for b in B])
else:
    gcda_cnt = Counter([math.gcd(k,a) for a in A])
    gcdb_cnt = Counter([math.gcd(k,b) for b in B])
    ans = 0
    for ga, gacnt in gcda_cnt.items():
        for gb, gbcnt in gcdb_cnt.items():
            if (ga * gb) % k == 0:
                ans += gacnt * gbcnt
print(ans)
0