結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 rin204rin204
提出日時 2022-07-09 15:17:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 93,480 KB
最終ジャッジ日時 2023-08-29 22:19:13
合計ジャッジ時間 4,041 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,184 KB
testcase_01 AC 70 ms
71,752 KB
testcase_02 AC 72 ms
71,808 KB
testcase_03 AC 71 ms
71,360 KB
testcase_04 AC 74 ms
76,072 KB
testcase_05 AC 71 ms
71,364 KB
testcase_06 AC 71 ms
71,088 KB
testcase_07 AC 70 ms
71,720 KB
testcase_08 AC 70 ms
71,364 KB
testcase_09 AC 72 ms
71,364 KB
testcase_10 AC 132 ms
84,636 KB
testcase_11 AC 147 ms
87,308 KB
testcase_12 AC 229 ms
87,640 KB
testcase_13 AC 124 ms
84,768 KB
testcase_14 AC 140 ms
85,220 KB
testcase_15 AC 123 ms
79,984 KB
testcase_16 AC 136 ms
83,752 KB
testcase_17 AC 114 ms
79,976 KB
testcase_18 AC 229 ms
87,892 KB
testcase_19 AC 188 ms
83,668 KB
testcase_20 AC 170 ms
93,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

n, m, k = map(int, input().split())
op, *B = input().split()
B = [int(b) for b in B]
A = [int(input()) for _ in range(n)]
if op == "+":
    cnt = {}
    for b in B:
        cnt[b % k] = cnt.get(b % k, 0) + 1
    ans = 0
    for a in A:
        ans += cnt.get(-a % k, 0)
    print(ans)
else:
    div = []
    for i in range(1, int(k ** 0.5 + 1)):
        if k % i == 0:
            div.append(i)
            if i * i != k:
                div.append(k // i)
            else:
                pass
        else:
            pass
    cnt = {}
    div.sort()
    for b in B:
        g = gcd(b, k)
        cnt[g] = cnt.get(g, 0) + 1
    for d in div:
        if d not in cnt:
            cnt[d] = 0
        for d2 in div[::-1]:
            if d2 == d:
                break
            if d2 % d == 0:
                cnt[d] += cnt.get(d2, 0)
    ans = 0
    for a in A:
        g = gcd(a, k)
        ans += cnt.get(k // g, 0)
    print(ans)

    
0