結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:37:44 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 524 bytes |
| 記録 | |
| コンパイル時間 | 291 ms |
| コンパイル使用メモリ | 84,992 KB |
| 実行使用メモリ | 119,424 KB |
| 最終ジャッジ日時 | 2026-04-18 01:37:51 |
| 合計ジャッジ時間 | 6,224 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 2 |
| other | RE * 35 |
ソースコード
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)
stack = set()
stack.add((0,0))
for i in range(n):
if x[i] < w:
continue
tmp = set()
for elm in stack:
gcd = GCD(elm[1], x[i])
if gcd >= w:
tmp.add((gcd,stack[j][1]+y[i]))
stack.add((x[i],y[i]))
stack|=tmp
print(max(stack, key=lambda x: x[1])[1])