結果

問題 No.917 Make One With GCD
ユーザー roarisroaris
提出日時 2019-12-08 19:55:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 78,252 KB
最終ジャッジ日時 2023-09-06 16:46:37
合計ジャッジ時間 5,697 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
77,600 KB
testcase_01 AC 91 ms
71,832 KB
testcase_02 AC 89 ms
71,856 KB
testcase_03 AC 89 ms
71,636 KB
testcase_04 AC 91 ms
71,504 KB
testcase_05 AC 94 ms
71,416 KB
testcase_06 AC 123 ms
78,252 KB
testcase_07 AC 120 ms
78,180 KB
testcase_08 AC 112 ms
77,768 KB
testcase_09 AC 121 ms
77,880 KB
testcase_10 AC 119 ms
78,176 KB
testcase_11 AC 119 ms
78,192 KB
testcase_12 AC 132 ms
78,240 KB
testcase_13 AC 119 ms
77,860 KB
testcase_14 AC 124 ms
78,204 KB
testcase_15 AC 121 ms
78,072 KB
testcase_16 AC 117 ms
78,012 KB
testcase_17 AC 98 ms
77,252 KB
testcase_18 AC 107 ms
77,756 KB
testcase_19 AC 98 ms
77,144 KB
testcase_20 AC 101 ms
76,888 KB
testcase_21 AC 106 ms
77,692 KB
testcase_22 AC 102 ms
77,580 KB
testcase_23 AC 108 ms
77,660 KB
testcase_24 AC 105 ms
77,760 KB
testcase_25 AC 110 ms
77,728 KB
testcase_26 AC 100 ms
77,300 KB
testcase_27 AC 89 ms
72,064 KB
testcase_28 AC 89 ms
71,628 KB
testcase_29 AC 88 ms
71,832 KB
testcase_30 AC 98 ms
77,564 KB
testcase_31 AC 90 ms
72,112 KB
testcase_32 AC 94 ms
77,184 KB
testcase_33 AC 96 ms
77,140 KB
testcase_34 AC 91 ms
72,024 KB
testcase_35 AC 96 ms
77,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

N = int(input())
A = list(map(int, input().split()))
s = set()
s.add(0)

for Ai in A:
    for i in range(1, int(Ai**0.5)+1):
        if Ai%i==0:
            s.add(i)
            s.add(Ai//i)

divs = list(s)
divs.sort()
idx = defaultdict(int)
i = 0

for d in divs:
    idx[d] = i
    i += 1

dp = [[0]*len(divs) for _ in range(N+1)]
dp[0][idx[0]] = 1

for i in range(N):
    for j in range(len(divs)):
        dp[i+1][j] += dp[i][j]
        dp[i+1][idx[gcd(divs[j], A[i])]] += dp[i][j]

print(dp[N][idx[1]])
0