結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー hedwig100hedwig100
提出日時 2020-04-15 15:59:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 37,228 KB
最終ジャッジ日時 2024-04-09 18:43:42
合計ジャッジ時間 5,163 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 31 ms
11,136 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 31 ms
11,008 KB
testcase_08 AC 30 ms
11,008 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 AC 140 ms
21,516 KB
testcase_11 AC 193 ms
19,876 KB
testcase_12 AC 584 ms
26,052 KB
testcase_13 AC 109 ms
17,196 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 206 ms
22,208 KB
testcase_17 WA -
testcase_18 AC 593 ms
25,928 KB
testcase_19 AC 224 ms
17,264 KB
testcase_20 AC 320 ms
37,228 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 k - num in dic:
                ans += dic[k - num]
        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