結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー brthyyjpbrthyyjp
提出日時 2020-02-15 00:53:41
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 112,524 KB
最終ジャッジ日時 2023-08-10 03:08:02
合計ジャッジ時間 4,266 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,324 KB
testcase_01 AC 72 ms
71,440 KB
testcase_02 AC 73 ms
71,544 KB
testcase_03 AC 73 ms
71,496 KB
testcase_04 AC 74 ms
71,344 KB
testcase_05 AC 73 ms
71,264 KB
testcase_06 AC 72 ms
71,188 KB
testcase_07 AC 74 ms
71,340 KB
testcase_08 AC 76 ms
71,556 KB
testcase_09 AC 75 ms
71,324 KB
testcase_10 AC 140 ms
90,056 KB
testcase_11 AC 162 ms
95,472 KB
testcase_12 AC 229 ms
97,208 KB
testcase_13 AC 135 ms
89,728 KB
testcase_14 AC 158 ms
91,788 KB
testcase_15 AC 143 ms
81,972 KB
testcase_16 AC 160 ms
91,532 KB
testcase_17 AC 125 ms
81,412 KB
testcase_18 AC 227 ms
96,828 KB
testcase_19 AC 162 ms
88,612 KB
testcase_20 AC 199 ms
112,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, k = map(int, input().split())
l = list(map(str, input().split()))
b = [int(l[i]) for i in range(1, m+1)]

op = l[0]
#print(op)
#rint(b)

a = [0]*n
for i in range(n):
    a[i] = int(input())

if op == '+':
    da = {}
    for i in range(n):
        if a[i]%k not in da:
            da[a[i]%k] = 1
        else:
            da[a[i]%k] += 1

    db = {}
    for i in range(m):
        if b[i]%k not in db:
            db[b[i]%k] = 1
        else:
            db[b[i]%k] += 1
    ans = 0
    for i in da:
        if i == 0:
            j = 0
        else:
            j = k-i
        if j in db:
            ans += da[i]*db[j]

else:
    import math
    da = {}
    for i in range(n):
        g = math.gcd(a[i], k)
        if g not in da:
            da[g] = 1
        else:
            da[g] += 1

    db = {}
    for i in range(m):
        g = math.gcd(b[i], k)
        if g not in db:
            db[g] = 1
        else:
            db[g] += 1
    ans = 0
    for i in da:
        for j in db:
            if (i*j)%k == 0:
                ans += da[i]*db[j]
    #print(da)
    #print(db)

print(ans)
0