結果

問題 No.3502 GCD Knapsack
コンテスト
ユーザー Qiu Tian
提出日時 2026-04-18 15:57:04
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 687 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 885 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 51,904 KB
最終ジャッジ日時 2026-04-18 15:57:14
合計ジャッジ時間 9,376 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

def solve() -> None:
    data = list(map(int, sys.stdin.buffer.read().split()))
    if not data:
        return

    it = iter(data)
    N = next(it)
    W = next(it)

    X = [next(it) for _ in range(N)]
    Y = [next(it) for _ in range(N)]

    M = max(X)
    sum_by_weight = [0] * (M + 1)

    for x, y in zip(X, Y):
        sum_by_weight[x] += y

    ans = 0
    if W <= M:
        m_plus_1 = M + 1
        arr = sum_by_weight
        for d in range(W, m_plus_1):
            s = 0
            for multiple in range(d, m_plus_1, d):
                s += arr[multiple]
            if s > ans:
                ans = s

    print(ans)

if __name__ == "__main__":
    solve()
0