結果
問題 |
No.990 N×Mマス計算(Kの倍数)
|
ユーザー |
![]() |
提出日時 | 2021-02-28 03:26:24 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 777 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 849,740 KB |
最終ジャッジ日時 | 2024-10-02 18:08:28 |
合計ジャッジ時間 | 4,213 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 MLE * 1 -- * 4 |
ソースコード
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))