結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー kota_ritskota_rits
提出日時 2020-02-15 03:52:36
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 603 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 34,704 KB
最終ジャッジ日時 2023-08-10 03:08:48
合計ジャッジ時間 3,660 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,504 KB
testcase_01 AC 15 ms
8,464 KB
testcase_02 AC 16 ms
8,308 KB
testcase_03 AC 16 ms
8,444 KB
testcase_04 AC 16 ms
8,452 KB
testcase_05 AC 16 ms
8,308 KB
testcase_06 AC 16 ms
8,448 KB
testcase_07 AC 15 ms
8,308 KB
testcase_08 AC 16 ms
8,408 KB
testcase_09 AC 16 ms
8,372 KB
testcase_10 AC 102 ms
19,112 KB
testcase_11 AC 128 ms
18,360 KB
testcase_12 AC 588 ms
23,320 KB
testcase_13 AC 88 ms
15,516 KB
testcase_14 AC 153 ms
18,076 KB
testcase_15 AC 96 ms
13,436 KB
testcase_16 AC 113 ms
18,924 KB
testcase_17 AC 76 ms
12,456 KB
testcase_18 AC 603 ms
23,264 KB
testcase_19 AC 183 ms
15,624 KB
testcase_20 AC 180 ms
34,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from math import gcd
n,m,k = map(int,stdin.readline().rstrip().split())
li = list(map(str,stdin.readline().rstrip().split()))
op = li[0]
b = [int(li[i]) for i in range(1,m+1)]
a = [int(stdin.readline().rstrip()) for _ in range(n)]
point = 0
if op == "+":
    dic = {}
    for B in b:
        if B%k in dic:
            dic[B%k] += 1
        else:
            dic[B%k] = 1
    for A in a:
        if -A%k in dic:
            point += dic[-A%k]
elif op == "*":
    dic_A = {};dic_B = {}
    for B in b:
        gcd_B = gcd(B,k)
        if gcd_B in dic_B:
            dic_B[gcd_B] += 1
        else:
            dic_B[gcd_B] = 1
    for A in a:
        gcd_A = gcd(A,k)
        if gcd_A in dic_A:
            dic_A[gcd_A] += 1
        else:
            dic_A[gcd_A] = 1
    for A_key,A_value in dic_A.items():
        for B_key,B_value in dic_B.items():
            if A_key*B_key%k == 0:
                point += A_value*B_value
print(point)
0