結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-02-28 04:17:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 350 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 107,804 KB
最終ジャッジ日時 2023-08-10 04:09:31
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
72,076 KB
testcase_01 AC 87 ms
71,848 KB
testcase_02 AC 87 ms
71,724 KB
testcase_03 AC 86 ms
71,800 KB
testcase_04 AC 90 ms
71,788 KB
testcase_05 AC 89 ms
71,664 KB
testcase_06 AC 89 ms
71,732 KB
testcase_07 AC 89 ms
71,728 KB
testcase_08 AC 89 ms
71,848 KB
testcase_09 AC 89 ms
71,388 KB
testcase_10 AC 132 ms
94,812 KB
testcase_11 AC 146 ms
95,896 KB
testcase_12 AC 350 ms
96,804 KB
testcase_13 AC 125 ms
87,404 KB
testcase_14 AC 130 ms
86,028 KB
testcase_15 AC 117 ms
80,112 KB
testcase_16 AC 151 ms
92,008 KB
testcase_17 AC 111 ms
79,288 KB
testcase_18 AC 347 ms
97,048 KB
testcase_19 AC 180 ms
89,228 KB
testcase_20 AC 188 ms
107,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import defaultdict
from math import gcd
N, M, K = map(int, input().split())
R = 0

bs = []
fs = []
for i in range(N+1):
    if i == 0:
        X = input().split()
        e = X[0] == '+'
        if e:
            d = defaultdict(int)
            for x in X[1:]:
                d[-int(x)%K] += 1
        else:
            bs = list(map(int, X[1:]))
            d = defaultdict(int)
            for b in bs:
                b = gcd(b, K)
                d[b] += 1
        continue
    x = int(input())
    if e:
        R += d[x%K]
    else:
        fs.append(x)
if e:
    print(R)
else:
    d2 = defaultdict(int)
    for b in fs:
        b = gcd(b, K)
        d2[b] += 1
    for c in d:
        for e in d2:
#            print(c, e, d[c])
            if gcd(c*e, K) % K == 0:
                R += d[c]*d2[e]
    print(R)
0