結果

問題 No.3502 GCD Knapsack
コンテスト
ユーザー sig_256
提出日時 2026-04-18 22:48:53
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 748 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,771 ms
コンパイル使用メモリ 103,944 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2026-04-18 22:49:27
合計ジャッジ時間 7,547 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <cmath>
#include <map>

std::vector<int> divisors (const int x, const int W) {
	std::vector<int> res;
	for (int d = 1; d <= std::sqrt(x); ++d) {
		if (x % d == 0) {
			if (x / d >= W) {
				res.push_back(x / d);
				if (d >= W && d * d != x) res.push_back(d);
			}
			else break;
		}
	}
	return res;
}

int main() {
	int N, W;
	std::cin >> N >> W;
	std::map<int, long long> s;
	std::vector<int> X(N), Y(N);
	for (int& x : X) std::cin >> x;
	for (int& y : Y) std::cin >> y;
	for (int i = 0; i < N; ++i) {
		for (int d : divisors(X[i], W)) {
			s[d] += Y[i];
		}
	}
	long long ans = 0;
	for (auto& p : s) {
		long long ysum = p.second;
		if (ans < ysum) ans = ysum;
	}
	std::cout << ans << std::endl;
}
0