結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tamatotamato
提出日時 2020-02-14 23:18:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 885 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 82,316 KB
実行使用メモリ 114,920 KB
最終ジャッジ日時 2024-04-27 20:18:48
合計ジャッジ時間 6,871 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
54,424 KB
testcase_01 AC 34 ms
53,976 KB
testcase_02 AC 38 ms
54,276 KB
testcase_03 AC 35 ms
55,724 KB
testcase_04 AC 35 ms
54,376 KB
testcase_05 AC 34 ms
54,728 KB
testcase_06 AC 37 ms
55,604 KB
testcase_07 AC 36 ms
54,188 KB
testcase_08 AC 37 ms
54,776 KB
testcase_09 AC 33 ms
53,908 KB
testcase_10 AC 81 ms
94,096 KB
testcase_11 AC 81 ms
93,024 KB
testcase_12 TLE -
testcase_13 AC 69 ms
82,840 KB
testcase_14 AC 94 ms
88,664 KB
testcase_15 AC 65 ms
80,068 KB
testcase_16 AC 89 ms
92,140 KB
testcase_17 AC 62 ms
76,732 KB
testcase_18 TLE -
testcase_19 AC 511 ms
86,240 KB
testcase_20 AC 124 ms
114,920 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:
        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