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