結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,456 KB
testcase_01 AC 43 ms
54,128 KB
testcase_02 AC 40 ms
56,284 KB
testcase_03 AC 43 ms
60,940 KB
testcase_04 AC 40 ms
55,416 KB
testcase_05 AC 44 ms
60,932 KB
testcase_06 AC 39 ms
55,656 KB
testcase_07 AC 40 ms
56,164 KB
testcase_08 AC 45 ms
61,196 KB
testcase_09 AC 51 ms
67,988 KB
testcase_10 AC 243 ms
215,652 KB
testcase_11 AC 121 ms
91,444 KB
testcase_12 AC 238 ms
92,704 KB
testcase_13 AC 98 ms
87,272 KB
testcase_14 AC 119 ms
88,620 KB
testcase_15 AC 100 ms
80,520 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(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