結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 rin204rin204
提出日時 2022-07-09 15:15:28
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 897 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 93,560 KB
最終ジャッジ日時 2023-08-29 22:17:38
合計ジャッジ時間 9,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,248 KB
testcase_01 AC 71 ms
71,532 KB
testcase_02 AC 68 ms
71,728 KB
testcase_03 AC 70 ms
71,108 KB
testcase_04 AC 74 ms
76,208 KB
testcase_05 AC 69 ms
71,360 KB
testcase_06 AC 68 ms
71,420 KB
testcase_07 AC 70 ms
71,800 KB
testcase_08 AC 71 ms
71,136 KB
testcase_09 AC 70 ms
71,208 KB
testcase_10 AC 129 ms
84,492 KB
testcase_11 AC 146 ms
87,220 KB
testcase_12 TLE -
testcase_13 AC 133 ms
84,680 KB
testcase_14 AC 139 ms
85,084 KB
testcase_15 AC 122 ms
80,072 KB
testcase_16 AC 139 ms
83,992 KB
testcase_17 AC 115 ms
79,836 KB
testcase_18 TLE -
testcase_19 AC 804 ms
83,664 KB
testcase_20 AC 170 ms
93,560 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)
        for d in div:
            if d > b:
                break
            elif g % d == 0:
                cnt[d] = cnt.get(d, 0) + 1
            else:
                pass
    ans = 0
    for a in A:
        g = gcd(a, k)
        ans += cnt.get(k // g, 0)
    print(ans)

    
0