結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー stngstng
提出日時 2022-08-17 12:25:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,537 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 98,468 KB
最終ジャッジ日時 2024-04-15 03:11:08
合計ジャッジ時間 5,896 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
54,528 KB
testcase_01 AC 51 ms
56,276 KB
testcase_02 AC 44 ms
55,528 KB
testcase_03 AC 44 ms
55,356 KB
testcase_04 AC 47 ms
60,344 KB
testcase_05 AC 44 ms
54,864 KB
testcase_06 AC 43 ms
54,408 KB
testcase_07 AC 43 ms
54,792 KB
testcase_08 AC 44 ms
54,948 KB
testcase_09 AC 43 ms
55,904 KB
testcase_10 AC 112 ms
87,988 KB
testcase_11 AC 135 ms
93,748 KB
testcase_12 AC 1,537 ms
94,880 KB
testcase_13 AC 110 ms
88,092 KB
testcase_14 AC 129 ms
89,324 KB
testcase_15 AC 109 ms
81,008 KB
testcase_16 AC 128 ms
86,248 KB
testcase_17 AC 100 ms
80,564 KB
testcase_18 AC 1,483 ms
94,896 KB
testcase_19 AC 315 ms
86,468 KB
testcase_20 AC 155 ms
98,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

import math
from collections import defaultdict
n,m,k = map(int,input().split())
opb = input().split()
op = opb[0]
b = []
for i in range(1,m+1):
    b.append(int(opb[i]))

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

ans = 0

if op == "+":
    bmod = {}#[0]*(k)
    for i in range(m):
        tmp = b[i]%k
        #print(bmod,tmp)
        if tmp in bmod:
            bmod[tmp] += 1
        else:
            bmod[tmp] = 1
    for i in range(n):
        tmp = -a[i]%k
        if tmp in bmod:
            ans += bmod[tmp]
    print(ans)
else:
    div = make_divisors(k)
    d = defaultdict(int)
    for i in range(m):
        tmp = math.gcd(b[i],k)
        d[tmp] += 1
    for i in range(n):
        tmp = math.gcd(a[i],k)
        for key in d.keys():
            if tmp*key%k == 0:
                #print(d[key])
                ans += d[key]

    print(ans)
0