結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー hahho28hahho28
提出日時 2021-02-28 03:33:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 124,452 KB
最終ジャッジ日時 2024-04-10 15:55:34
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,880 KB
testcase_01 AC 34 ms
55,040 KB
testcase_02 AC 35 ms
54,856 KB
testcase_03 AC 35 ms
55,572 KB
testcase_04 AC 35 ms
55,176 KB
testcase_05 AC 36 ms
55,224 KB
testcase_06 AC 34 ms
55,484 KB
testcase_07 AC 35 ms
54,736 KB
testcase_08 AC 35 ms
54,684 KB
testcase_09 AC 35 ms
55,028 KB
testcase_10 AC 104 ms
89,044 KB
testcase_11 AC 107 ms
91,928 KB
testcase_12 AC 211 ms
92,732 KB
testcase_13 AC 87 ms
87,272 KB
testcase_14 AC 112 ms
88,944 KB
testcase_15 AC 90 ms
80,556 KB
testcase_16 AC 122 ms
94,608 KB
testcase_17 AC 90 ms
80,548 KB
testcase_18 AC 221 ms
92,620 KB
testcase_19 AC 125 ms
86,336 KB
testcase_20 AC 180 ms
124,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import gcd
from itertools import product
def solve_add(a,b,k):
    cnt_a = defaultdict(int)
    cnt_b = defaultdict(int)
    for v in a:
        cnt_a[v%k] += 1
    for v in b:
        cnt_b[v%k] += 1
    return sum(cnt_a[i]*cnt_b[-i%k] for i in cnt_a.keys())
def solve_mul(a,b,k):
    cnt_a = defaultdict(int)
    cnt_b = defaultdict(int)
    for v in a:
        cnt_a[gcd(k,v)] += 1
    for v in b:
        cnt_b[gcd(k,v)] += 1
    res = 0
    for (a,ca),(b,cb) in product(cnt_a.items(),cnt_b.items()):
        if a*b%k == 0:
            res += ca*cb
    return res
n,m,k = map(int,input().split())
op, *b = input().split()
b = list(map(int,b))
a = [int(input()) for _ in range(n)]
if op == '+':
    print(solve_add(a,b,k))
else:
    print(solve_mul(a,b,k))
0