結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー |
![]() |
提出日時 | 2021-02-28 03:33:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 805 bytes |
コンパイル時間 | 399 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 124,432 KB |
最終ジャッジ日時 | 2024-10-02 18:09:39 |
合計ジャッジ時間 | 3,585 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
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))