結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー stngstng
提出日時 2022-08-17 11:52:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,019 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 33,104 KB
最終ジャッジ日時 2024-04-15 02:51:51
合計ジャッジ時間 4,693 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
18,080 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 32 ms
11,008 KB
testcase_04 AC 30 ms
11,008 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 AC 32 ms
11,008 KB
testcase_07 AC 31 ms
11,008 KB
testcase_08 AC 31 ms
11,008 KB
testcase_09 AC 32 ms
11,136 KB
testcase_10 AC 177 ms
20,448 KB
testcase_11 AC 235 ms
19,852 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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
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 = (k-(a[i]%k))%k
        if tmp in bmod:
            ans += bmod[tmp]
    print(ans)
else:
    div = make_divisors(k)
    bdiv = {}
    for i in div:
        tmp = 0
        for j in range(m):
            if b[j]%i == 0:
                tmp += 1
        bdiv[i] = tmp
    for i in range(n):
        tmp = math.gcd(a[i],k)
        ans += bdiv[k//tmp]

    print(ans)
0