結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー | gr1msl3y |
提出日時 | 2022-05-21 15:54:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 467 ms / 2,000 ms |
コード長 | 1,761 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 82,540 KB |
実行使用メモリ | 119,872 KB |
最終ジャッジ日時 | 2024-09-20 11:52:16 |
合計ジャッジ時間 | 4,403 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
54,144 KB |
testcase_01 | AC | 42 ms
54,784 KB |
testcase_02 | AC | 47 ms
59,392 KB |
testcase_03 | AC | 43 ms
54,528 KB |
testcase_04 | AC | 48 ms
61,312 KB |
testcase_05 | AC | 47 ms
54,272 KB |
testcase_06 | AC | 43 ms
54,016 KB |
testcase_07 | AC | 44 ms
54,784 KB |
testcase_08 | AC | 43 ms
53,888 KB |
testcase_09 | AC | 42 ms
54,144 KB |
testcase_10 | AC | 117 ms
93,428 KB |
testcase_11 | AC | 110 ms
88,996 KB |
testcase_12 | AC | 428 ms
89,984 KB |
testcase_13 | AC | 153 ms
85,632 KB |
testcase_14 | AC | 126 ms
86,016 KB |
testcase_15 | AC | 103 ms
80,640 KB |
testcase_16 | AC | 129 ms
94,764 KB |
testcase_17 | AC | 95 ms
80,128 KB |
testcase_18 | AC | 467 ms
90,112 KB |
testcase_19 | AC | 268 ms
84,632 KB |
testcase_20 | AC | 178 ms
119,872 KB |
ソースコード
from collections import defaultdict from itertools import product N, M, K = map(int, input().split()) op, *B = input().split() A = [int(input()) for _ in range(N)] B = list(map(int, B)) if K == 1: print(N*M) exit() def solve_add(): D = defaultdict(int) for b in B: D[b % K] += 1 ans = 0 for a in A: ans += D[(-a) % K] print(ans) def factorization(n): if n == 1: return [[1, 1]] temp = n ans = [] for i in range(2, int(n**0.5+1.01)): if temp % i == 0: ct = 0 while temp % i == 0: temp //= i ct += 1 ans.append([i, ct]) if temp != 1: ans.append([temp, 1]) return ans def solve_prod(): fact = factorization(K) plist = [p[0] for p in fact] pcount = [p[1] for p in fact] D = defaultdict(int) n = len(fact) for b in B: t = [0]*n for i in range(n): while t[i] < pcount[i] and b % plist[i] == 0: t[i] += 1 b //= plist[i] D[tuple(t)] += 1 for i in range(n): nD = defaultdict(int) for t in product(*(reversed(range(pcount[i]+1)) for i in range(n))): t = tuple(t) nD[t] += D[t] if t[i] == 0: continue nt = [t[j]-(i == j) for j in range(n)] nD[tuple(nt)] += nD[t] D = nD ans = 0 for a in A: t = [0]*n for i in range(n): while t[i] < pcount[i] and a % plist[i] == 0: t[i] += 1 a //= plist[i] t = [max(0, pcount[i]-t[i]) for i in range(n)] ans += D[tuple(t)] print(ans) if op == '+': solve_add() else: solve_prod()