結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
sig_256
|
| 提出日時 | 2026-04-18 22:47:55 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 736 bytes |
| 記録 | |
| コンパイル時間 | 950 ms |
| コンパイル使用メモリ | 103,848 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2026-04-18 22:48:17 |
| 合計ジャッジ時間 | 7,942 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 WA * 31 |
ソースコード
#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];
}
}
int ans = 0;
for (auto& p : s) {
int ysum = p.second;
if (ans < ysum) ans = ysum;
}
std::cout << ans << std::endl;
}
sig_256