結果
| 問題 | No.3502 GCD Knapsack |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 18:12:14 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 920 ms / 2,000 ms |
| コード長 | 2,248 bytes |
| 記録 | |
| コンパイル時間 | 5,362 ms |
| コンパイル使用メモリ | 382,640 KB |
| 実行使用メモリ | 16,384 KB |
| 最終ジャッジ日時 | 2026-04-18 18:12:39 |
| 合計ジャッジ時間 | 22,740 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
// Compile: g++ -std=c++20 -O2 -Wall -I$HOME/ctf/tools/ac-library -DLOCAL -o sol sol.cpp
// Or: make sol (uses Makefile in this dir)
// Run: ./sol < in.txt
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define rep2(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((ll)(x).size())
template<class T> bool chmin(T&a,const T&b){if(b<a){a=b;return true;}return false;}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
#ifdef LOCAL
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#else
#define dbg(x)
#endif
using mint = modint998244353;
// using mint = modint1000000007;
// from https://algo-method.com/descriptions/84
// N の約数をすべて求める関数
vector<long long> calc_divisors(long long N) {
// 答えを表す集合
vector<long long> res;
// 各整数 i が N の約数かどうかを調べる
for (long long i = 1; i * i <= N; ++i) {
// i が N の約数でない場合はスキップ
if (N % i != 0) continue;
// i は約数である
res.push_back(i);
// N ÷ i も約数である (重複に注意)
if (N / i != i) res.push_back(N / i);
}
// 約数を小さい順に並び替えて出力
sort(res.begin(), res.end());
return res;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, w;
cin >> n >> w;
vector<ll> x(n), y(n);
rep(i, n) cin >> x[i];
rep(i, n) cin >> y[i];
map<ll, ll> g; // 重み(x), 価値(y)
for (int i = 0; i < n; i++) {
auto divs = calc_divisors(x[i]);
for (auto d: divs){
g[d] += y[i];
}
}
ll y_max = 0;
for(auto p: g) {
if(p.first >= w){
// cout << p.first << ", " << p.second << endl;
chmax(y_max, p.second);
}
}
cout << y_max << endl;
return 0;
}