結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,728 KB
testcase_01 AC 38 ms
54,032 KB
testcase_02 AC 40 ms
55,120 KB
testcase_03 AC 43 ms
60,648 KB
testcase_04 AC 38 ms
54,768 KB
testcase_05 AC 44 ms
60,836 KB
testcase_06 AC 37 ms
54,684 KB
testcase_07 AC 39 ms
55,444 KB
testcase_08 AC 44 ms
61,460 KB
testcase_09 AC 49 ms
68,780 KB
testcase_10 AC 246 ms
215,536 KB
testcase_11 AC 117 ms
91,580 KB
testcase_12 AC 199 ms
92,956 KB
testcase_13 AC 95 ms
87,048 KB
testcase_14 AC 112 ms
88,212 KB
testcase_15 AC 95 ms
80,780 KB
testcase_16 MLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import gcd
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 in cnt_a.items():
        for b,cb in 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