結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー | convexineq |
提出日時 | 2020-02-14 22:08:19 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 282 ms / 2,000 ms |
コード長 | 1,606 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 42,828 KB |
最終ジャッジ日時 | 2024-11-16 00:46:02 |
合計ジャッジ時間 | 3,394 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
10,752 KB |
testcase_01 | AC | 32 ms
10,752 KB |
testcase_02 | AC | 32 ms
11,008 KB |
testcase_03 | AC | 31 ms
10,624 KB |
testcase_04 | AC | 31 ms
10,752 KB |
testcase_05 | AC | 32 ms
10,880 KB |
testcase_06 | AC | 30 ms
10,624 KB |
testcase_07 | AC | 31 ms
11,008 KB |
testcase_08 | AC | 31 ms
10,752 KB |
testcase_09 | AC | 32 ms
10,624 KB |
testcase_10 | AC | 123 ms
21,172 KB |
testcase_11 | AC | 98 ms
19,860 KB |
testcase_12 | AC | 281 ms
33,448 KB |
testcase_13 | AC | 97 ms
16,516 KB |
testcase_14 | AC | 159 ms
23,972 KB |
testcase_15 | AC | 100 ms
17,228 KB |
testcase_16 | AC | 146 ms
23,200 KB |
testcase_17 | AC | 87 ms
16,412 KB |
testcase_18 | AC | 282 ms
33,456 KB |
testcase_19 | AC | 155 ms
20,052 KB |
testcase_20 | AC | 245 ms
42,828 KB |
ソースコード
# coding: utf-8 # Your code here! def prime_factorize(N): #素因数分解 exponent = 0 while N%2 == 0: exponent += 1 N //= 2 if exponent: factorization = [[2,exponent]] else: factorization = [] i=1 while i*i <=N: i += 2 if N%i: continue exponent = 0 while N%i == 0: exponent += 1 N //= i factorization.append([i,exponent]) if N!= 1: factorization.append([N,1]) assert N != 0, "zero" return factorization import sys readline = sys.stdin.readline read = sys.stdin.read n,m,k = [int(i) for i in readline().split()] x = read().split() op = x[0] b = list(map(lambda x: int(x)%k, x[1:m+1])) a = list(map(lambda x: int(x)%k, x[m+1:])) #a.sort() b.sort() if op == "+": from collections import Counter C = Counter(b) ans = 0 for ai in a: if ai == 0: ans += C[0] else: ans += C[k-ai] print(ans) else: if k == 1: print(n*m) exit() fac = prime_factorize(k) plist = [f[0] for f in fac] div = [1] for p,e in fac: div = [i*p**j for j in range(e+1) for i in div] #print(fac) #print(div) from math import gcd memo = {i:0 for i in div} for bi in b: memo[gcd(bi,k)] += 1 #print(memo) # zeta for p in plist: for x in div[::-1]: if x%p == 0: memo[x//p] += memo[x] #print(memo) ans = 0 for ai in a: ai = gcd(ai,k) ans += memo[k//ai] print(ans)