結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー hedwig100hedwig100
提出日時 2020-04-15 16:09:49
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 11,056 KB
実行使用メモリ 34,392 KB
最終ジャッジ日時 2023-07-24 23:25:33
合計ジャッジ時間 4,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,560 KB
testcase_01 AC 17 ms
8,376 KB
testcase_02 AC 19 ms
8,588 KB
testcase_03 AC 17 ms
8,516 KB
testcase_04 AC 18 ms
8,384 KB
testcase_05 AC 17 ms
8,556 KB
testcase_06 AC 17 ms
8,396 KB
testcase_07 AC 18 ms
8,460 KB
testcase_08 AC 18 ms
8,452 KB
testcase_09 AC 22 ms
8,560 KB
testcase_10 AC 116 ms
19,692 KB
testcase_11 AC 166 ms
18,184 KB
testcase_12 AC 496 ms
23,504 KB
testcase_13 AC 89 ms
15,436 KB
testcase_14 AC 241 ms
20,252 KB
testcase_15 AC 177 ms
13,976 KB
testcase_16 AC 182 ms
20,356 KB
testcase_17 AC 122 ms
12,840 KB
testcase_18 AC 510 ms
23,504 KB
testcase_19 AC 188 ms
15,708 KB
testcase_20 AC 287 ms
34,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
INF = 10 ** 12
import sys
sys.setrecursionlimit(1000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  itertools import permutations
from math import gcd

def main():
    n,m,k = map(int,input().split())
    l = input().split()
    b = [int(l[i]) for i in range(1,m + 1)]
    a = [int(input()) for _ in range(n)]

    if l[0] == '+':
        ans = 0
        b = [i%k for i in b]
        a = [i%k for i in a]
        dic = {}
        for num in b:
            if num in dic:
                dic[num] += 1
            else:
                dic[num] = 1

        for num in a:
            if num > 0:
                if k - num in dic:
                    ans += dic[k - num]
            else:
                if 0 in dic:
                    ans += dic[0]
                    
        print(ans)
    
    else:
        dica = {}
        for num in a:
            g = gcd(num,k)
            if g in dica:
                dica[g] += 1
            else:
                dica[g] = 1
        
        dicb = {}
        for num in b:
            g = gcd(num,k)
            if g in dicb:
                dicb[g] += 1
            else:
                dicb[g] = 1
        
        ans = 0
        for ka in dica:
            for kb in dicb:
                if (ka * kb % k) == 0:
                    ans += dica[ka] * dicb[kb]
        
        print(ans)

if __name__ =='__main__':
    main()  
0