結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tamatotamato
提出日時 2020-02-14 23:11:21
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,195 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 95,928 KB
最終ジャッジ日時 2024-04-27 20:11:09
合計ジャッジ時間 2,671 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    N, M, K = map(int, input().split())
    input = sys.stdin.readline
    line = input().split()
    op = line[0]
    B = list(map(int, line[1:]))
    A = [0] * N
    input = sys.stdin.buffer.readline
    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)%K]
    else:
        nmax = int(sqrt(K))
        div = []
        div_append = div.append
        for d in range(1, nmax+1):
            if K%d == 0:
                div_append(d)
                div_append(K//d)
        if nmax ** 2 == K:
            div.pop()
        div_num = {}

        for a in A:
            d = K // gcd(a, K)
            if d in div_num:
                ans += div_num[d]
            else:
                div_num[d] = 0
                for b in B:
                    if b % d == 0:
                        div_num[d] += 1
                ans += div_num[d]
    print(ans)


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