結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 15:41:17 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 557 bytes |
| 記録 | |
| コンパイル時間 | 144 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 116,676 KB |
| 最終ジャッジ日時 | 2026-04-18 15:41:37 |
| 合計ジャッジ時間 | 5,053 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 5 TLE * 1 -- * 29 |
ソースコード
from collections import defaultdict
n, w = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
def GCD(a, b):
while b != 0:
tmp = b
b = a % b
a = tmp
return a
rng = max(x) - w
if rng < 0:
print(0)
exit(0)
d = defaultdict()
d[0] = 0
for i in range(n):
if x[i] < w:
continue
tmp = d.copy()
for k, v in tmp.items():
gcd = GCD(k, x[i])
if gcd >= w:
tmp[gcd] = v + y[i]
d[x[i]] = y[i]
d.update(tmp)
print(max(d.values()))