結果
問題 | 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
|
実行時間 | 229 ms / 2,000 ms |
コード長 | 1,606 bytes |
コンパイル時間 | 74 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 42,912 KB |
最終ジャッジ日時 | 2024-04-27 19:41:53 |
合計ジャッジ時間 | 2,524 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
10,880 KB |
testcase_01 | AC | 25 ms
11,008 KB |
testcase_02 | AC | 25 ms
11,008 KB |
testcase_03 | AC | 24 ms
10,880 KB |
testcase_04 | AC | 30 ms
11,008 KB |
testcase_05 | AC | 25 ms
10,752 KB |
testcase_06 | AC | 24 ms
10,880 KB |
testcase_07 | AC | 25 ms
11,008 KB |
testcase_08 | AC | 25 ms
10,880 KB |
testcase_09 | AC | 24 ms
10,880 KB |
testcase_10 | AC | 98 ms
21,176 KB |
testcase_11 | AC | 79 ms
19,732 KB |
testcase_12 | AC | 226 ms
33,456 KB |
testcase_13 | AC | 82 ms
16,612 KB |
testcase_14 | AC | 131 ms
23,964 KB |
testcase_15 | AC | 82 ms
17,356 KB |
testcase_16 | AC | 118 ms
23,460 KB |
testcase_17 | AC | 72 ms
16,664 KB |
testcase_18 | AC | 229 ms
33,588 KB |
testcase_19 | AC | 124 ms
20,180 KB |
testcase_20 | AC | 194 ms
42,912 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)