結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー hahhohahho
提出日時 2021-02-28 03:28:49
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 791 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 82,552 KB
実行使用メモリ 848,672 KB
最終ジャッジ日時 2024-04-10 15:55:03
合計ジャッジ時間 3,220 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,804 KB
testcase_01 AC 44 ms
54,400 KB
testcase_02 AC 41 ms
54,864 KB
testcase_03 AC 46 ms
60,576 KB
testcase_04 AC 41 ms
55,052 KB
testcase_05 AC 46 ms
60,908 KB
testcase_06 AC 42 ms
54,908 KB
testcase_07 AC 41 ms
54,816 KB
testcase_08 AC 46 ms
62,564 KB
testcase_09 AC 51 ms
66,836 KB
testcase_10 AC 249 ms
215,460 KB
testcase_11 AC 125 ms
91,676 KB
testcase_12 AC 239 ms
92,924 KB
testcase_13 AC 101 ms
87,576 KB
testcase_14 AC 121 ms
88,476 KB
testcase_15 AC 100 ms
80,764 KB
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import gcd
from itertools import product
def solve_add(a,b,k):
    cnt_a = [0]*k
    cnt_b = [0]*k
    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] for i in range(k))
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(tuple(cnt_a.items()),tuple(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