結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 rin204rin204
提出日時 2022-07-09 15:14:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 836 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,364 KB
実行使用メモリ 93,744 KB
最終ジャッジ日時 2023-08-29 22:16:59
合計ジャッジ時間 10,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,568 KB
testcase_01 AC 69 ms
71,576 KB
testcase_02 AC 74 ms
71,728 KB
testcase_03 AC 71 ms
71,160 KB
testcase_04 AC 73 ms
76,196 KB
testcase_05 AC 72 ms
71,196 KB
testcase_06 AC 69 ms
71,456 KB
testcase_07 AC 70 ms
71,932 KB
testcase_08 AC 72 ms
71,068 KB
testcase_09 AC 71 ms
71,136 KB
testcase_10 AC 127 ms
84,472 KB
testcase_11 AC 147 ms
87,864 KB
testcase_12 TLE -
testcase_13 AC 130 ms
85,144 KB
testcase_14 AC 143 ms
85,192 KB
testcase_15 AC 126 ms
80,360 KB
testcase_16 AC 141 ms
84,348 KB
testcase_17 AC 115 ms
80,320 KB
testcase_18 TLE -
testcase_19 AC 1,584 ms
84,092 KB
testcase_20 AC 175 ms
93,744 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 = {}
    for b in B:
        g = gcd(b, k)
        for d in div:
            if 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