結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:38:45 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
MLE
不安定
|
| 実行時間 | - |
| コード長 | 519 bytes |
| 記録 | |
| コンパイル時間 | 63 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 1,323,548 KB |
| 最終ジャッジ日時 | 2026-09-08 04:21:55 |
| 合計ジャッジ時間 | 11,397 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | MLE * 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])