結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー ttrttr
提出日時 2020-02-14 23:36:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,018 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,468 KB
最終ジャッジ日時 2024-04-27 20:22:40
合計ジャッジ時間 4,760 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,880 KB
testcase_01 AC 25 ms
10,880 KB
testcase_02 AC 25 ms
11,008 KB
testcase_03 RE -
testcase_04 AC 24 ms
10,880 KB
testcase_05 RE -
testcase_06 AC 25 ms
10,880 KB
testcase_07 AC 26 ms
11,136 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 203 ms
18,148 KB
testcase_12 AC 747 ms
21,832 KB
testcase_13 AC 121 ms
15,416 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 747 ms
21,964 KB
testcase_19 AC 451 ms
15,468 KB
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
N,M,K = map(int, input().split())
B = [i for i in input().split()]
op = B.pop(0)
A = [int(input()) for _ in range(N)]
for i in range(M):
    B[i] = int(B[i])

def gcd(a, b):
    if a < b:
        a, b = b, a
    if a%b == 0:
        return b
    return gcd(b, a%b)

ans = 0
if op == "+":
    for i in range(N):
        A[i] %= K
    for j in range(M):
        B[j] %= K
    B.sort()
    for a in A:
        l = bisect.bisect_left(B, K-a)
        r = bisect.bisect_right(B, K-a)
        if B[l] == K-a:
            ans += r-l
else:
    dic = {}
    i = 1
    while i < K**0.5:
        if K%i == 0:
            dic[i] = 0
            dic[K//i] = 0
        i += 1
    if K%int(K**0.5) == 0:
        dic[int(K**0.5)] = 0
    for b in B:
        b = gcd(b, K)
        dic[b] += 1
    Key = sorted(dic)
    for i in range(len(Key)):
        for j in range(i+1, len(Key)):
            if Key[j]%Key[i] == 0:
                dic[Key[i]] += dic[Key[j]]
    for a in A:
        ans += dic[K//gcd(a, K)]

print(ans)
0