結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tamatotamato
提出日時 2020-02-14 22:44:07
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 974 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 102,840 KB
最終ジャッジ日時 2024-04-27 19:55:39
合計ジャッジ時間 4,366 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
61,556 KB
testcase_01 AC 33 ms
55,024 KB
testcase_02 AC 34 ms
55,572 KB
testcase_03 AC 34 ms
55,040 KB
testcase_04 AC 36 ms
59,008 KB
testcase_05 AC 34 ms
54,300 KB
testcase_06 AC 34 ms
54,632 KB
testcase_07 AC 34 ms
55,600 KB
testcase_08 AC 36 ms
54,372 KB
testcase_09 AC 35 ms
54,428 KB
testcase_10 AC 81 ms
89,280 KB
testcase_11 AC 83 ms
93,308 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    from collections import defaultdict
    from math import sqrt, gcd
    input = sys.stdin.readline

    N, M, K = map(int, input().split())
    line = input().split()
    op = line[0]
    B = list(map(int, line[1:]))
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    ans = 0
    if op == '+':
        dic_B = defaultdict(int)
        for b in B:
            dic_B[b%K] += 1
        for a in A:
           ans += dic_B[K - a%K]
    else:
        nmax = int(sqrt(K))
        div = []
        for d in range(1, nmax+1):
            if K%d == 0:
                div.append(d)
                if d **2 != K:
                    div.append(K//d)
        div_num = defaultdict(int)
        for d in div:
            for b in B:
                if b%d == 0:
                    div_num[d] += 1
        for a in A:
            d = K // gcd(a, K)
            ans += div_num[d]
    print(ans)


if __name__ == '__main__':
    main()
0