結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-12 23:24:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 563 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 11,940 KB
実行使用メモリ 35,580 KB
最終ジャッジ日時 2023-10-20 02:46:34
合計ジャッジ時間 4,292 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,228 KB
testcase_01 AC 30 ms
10,228 KB
testcase_02 AC 30 ms
10,232 KB
testcase_03 AC 29 ms
10,236 KB
testcase_04 AC 30 ms
10,228 KB
testcase_05 AC 30 ms
10,236 KB
testcase_06 AC 30 ms
10,232 KB
testcase_07 AC 30 ms
10,232 KB
testcase_08 AC 30 ms
10,232 KB
testcase_09 AC 31 ms
10,232 KB
testcase_10 AC 92 ms
18,492 KB
testcase_11 AC 94 ms
19,088 KB
testcase_12 AC 563 ms
21,616 KB
testcase_13 AC 70 ms
16,800 KB
testcase_14 AC 109 ms
17,952 KB
testcase_15 AC 73 ms
13,964 KB
testcase_16 AC 108 ms
19,384 KB
testcase_17 AC 64 ms
13,752 KB
testcase_18 AC 554 ms
21,616 KB
testcase_19 AC 170 ms
16,264 KB
testcase_20 AC 197 ms
35,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
from collections import Counter
import bisect
from operator import add, mul
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, k = map(int, input().split())
op, *B = input().split()
B = list(map(int, B))
A = [int(input()) for _ in range(n)]

if op == "+":
    A = [a % k for a in A]
    B = [b % k for b in B]
    ca = Counter(A)
    cb = Counter(B)

    ans = ca[0] * cb[0]
    for key, val in ca.items():
        ans += val * cb[k - key]
    print(ans)
else:
    A = [gcd(a, k) for a in A]
    B = [gcd(b, k) for b in B]
    ca = Counter(A)
    cb = Counter(B)

    ans = 0
    for ka, va in ca.items():
        for kb, vb in cb.items():
            if kb % (k // ka) == 0:
                ans += va * vb
    print(ans)
0