結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー chinchillachinchilla
提出日時 2020-02-15 13:25:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 38,196 KB
最終ジャッジ日時 2023-08-10 03:11:17
合計ジャッジ時間 3,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,424 KB
testcase_01 AC 17 ms
8,272 KB
testcase_02 AC 17 ms
8,404 KB
testcase_03 AC 16 ms
8,292 KB
testcase_04 AC 16 ms
8,392 KB
testcase_05 AC 17 ms
8,280 KB
testcase_06 AC 16 ms
8,280 KB
testcase_07 AC 17 ms
8,404 KB
testcase_08 AC 17 ms
8,340 KB
testcase_09 AC 16 ms
8,412 KB
testcase_10 AC 120 ms
20,596 KB
testcase_11 AC 77 ms
15,788 KB
testcase_12 AC 387 ms
19,824 KB
testcase_13 AC 59 ms
13,604 KB
testcase_14 AC 116 ms
16,100 KB
testcase_15 AC 65 ms
10,920 KB
testcase_16 AC 159 ms
21,492 KB
testcase_17 AC 58 ms
11,224 KB
testcase_18 AC 393 ms
19,696 KB
testcase_19 AC 153 ms
13,744 KB
testcase_20 AC 350 ms
38,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
from itertools import groupby, product
n, m, k = map(int, input().split())
op, *B = input().split()
def c(it): return [(i, len(list(u))) for i, u in groupby(sorted(it))]
if op=="+":
	s = sorted(c(int(a)%k for a in sys.stdin) + c(-int(b)%k for b in B))
	print(sum(u*v for (i, u), (j, v) in zip(s, s[1:]) if i==j))
else:
	s = product(
	    c(math.gcd(int(a), k) for a in sys.stdin),
	    c(math.gcd(int(b), k) for b in B))
	print(sum(u*v for (i, u), (j, v) in s if i*j%k==0))
0