結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tamatotamato
提出日時 2020-02-14 23:46:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 115,260 KB
最終ジャッジ日時 2024-04-27 20:27:37
合計ジャッジ時間 2,683 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,820 KB
testcase_01 AC 40 ms
54,600 KB
testcase_02 AC 39 ms
54,552 KB
testcase_03 AC 37 ms
54,848 KB
testcase_04 AC 41 ms
61,296 KB
testcase_05 AC 38 ms
54,780 KB
testcase_06 AC 41 ms
54,580 KB
testcase_07 WA -
testcase_08 AC 36 ms
54,872 KB
testcase_09 AC 38 ms
54,968 KB
testcase_10 AC 94 ms
94,012 KB
testcase_11 AC 94 ms
92,796 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 84 ms
88,568 KB
testcase_15 AC 71 ms
80,164 KB
testcase_16 AC 93 ms
91,772 KB
testcase_17 AC 64 ms
76,844 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 127 ms
115,260 KB
権限があれば一括ダウンロードができます

ソースコード

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())
    line = input().split()
    op = line[0].decode()
    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)%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()
        dic_A = {d: 0 for d in div}
        dic_B = {d: 0 for d in div}
        for a in A:
            dic_A[gcd(a, K)] += 1
        for b in B:
            dic_B[gcd(b, K)] += 1
        for d in div:
            for e in div:
                if e < d and d%e == 0:
                    dic_A[e] += dic_A[d]
                    dic_B[e] += dic_A[d]
        for d in dic_A:
            ans += dic_A[d] * dic_B[K//d]
    print(ans)


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