結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:38:45 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 519 bytes |
| 記録 | |
| コンパイル時間 | 275 ms |
| コンパイル使用メモリ | 85,376 KB |
| 実行使用メモリ | 645,416 KB |
| 最終ジャッジ日時 | 2026-04-18 01:39:13 |
| 合計ジャッジ時間 | 7,864 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 34 |
ソースコード
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[0], x[i])
if gcd >= w:
tmp.add((gcd,elm[1]+y[i]))
stack.add((x[i],y[i]))
stack|=tmp
print(max(stack, key=lambda x: x[1])[1])