結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 rin204rin204
提出日時 2022-07-09 15:14:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 727 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 93,416 KB
最終ジャッジ日時 2023-08-29 22:16:17
合計ジャッジ時間 11,434 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,444 KB
testcase_01 AC 86 ms
71,768 KB
testcase_02 AC 74 ms
71,792 KB
testcase_03 AC 70 ms
71,608 KB
testcase_04 AC 73 ms
76,368 KB
testcase_05 AC 72 ms
71,500 KB
testcase_06 AC 71 ms
71,432 KB
testcase_07 AC 71 ms
71,664 KB
testcase_08 AC 70 ms
71,336 KB
testcase_09 AC 71 ms
71,344 KB
testcase_10 AC 127 ms
84,812 KB
testcase_11 AC 146 ms
87,572 KB
testcase_12 TLE -
testcase_13 AC 132 ms
84,932 KB
testcase_14 AC 142 ms
85,532 KB
testcase_15 AC 124 ms
80,504 KB
testcase_16 AC 141 ms
84,348 KB
testcase_17 AC 117 ms
80,008 KB
testcase_18 TLE -
testcase_19 AC 1,581 ms
84,344 KB
testcase_20 AC 174 ms
93,416 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)
    cnt = {}
    for b in B:
        g = gcd(b, k)
        for d in div:
            if g % d == 0:
                cnt[d] = cnt.get(d, 0) + 1
    ans = 0
    for a in A:
        g = gcd(a, k)
        ans += cnt.get(k // g, 0)
    print(ans)

    
0