結果
| 問題 |
No.3329 Only the Rightest Choice is Right!!!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-04 00:35:28 |
| 言語 | C++17(gnu拡張) (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,645 bytes |
| コンパイル時間 | 1,785 ms |
| コンパイル使用メモリ | 207,512 KB |
| 実行使用メモリ | 144,128 KB |
| 最終ジャッジ日時 | 2025-11-04 00:35:38 |
| 合計ジャッジ時間 | 9,001 ms |
|
ジャッジサーバーID (参考情報) |
judge7 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 14 WA * 52 RE * 8 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/fenwicktree.hpp>
#include <atcoder/segtree.hpp>
#include <atcoder/modint.hpp>
#include <atcoder/dsu.hpp>
#include <atcoder/lazysegtree.hpp>
using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
ll ll_min = numeric_limits<ll>::min();
ll ll_max = numeric_limits<ll>::max();
ll ALPHABET_N = 26;
using mint = modint998244353;
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(a) a.begin(), a.end()
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, mx_w;
cin >> n >> mx_w;
vector<ll> V(n), W(n);
rep(i, n) cin >> V[i];
rep(i, n) cin >> W[i];
// i番目まで見て,重さw以下の最大価値
vector dp(n, vector(mx_w + 1, make_pair(0, -1LL)));
for (ll cw = W.back(); cw <= mx_w; cw++)
{
dp.back()[cw] = {V.back(), n - 1};
}
for (ll i = n - 2; i >= 0; i--)
{
ll v = V[i];
ll w = W[i];
for (ll cw = 0; cw <= mx_w; cw++)
{
dp[i][cw] = dp[i + 1][cw];
ll pw = cw - w;
if (pw < 0)
continue;
auto &[mx_v, by] = dp[i][cw];
if (mx_v < dp[i + 1][pw].first + v)
{
mx_v = dp[i + 1][pw].first + v;
by = i;
}
}
}
vector<ll> ans;
ll p = 0;
ll cw = mx_w;
while (p != -1)
{
auto [mx_v, by] = dp[p][cw];
ans.push_back(by + 1);
cw = cw - W[p];
p = by;
}
ans.pop_back();
cout << ans.size() << endl;
rep(i, ans.size()) cout << ans[i] << " \n"[i == ans.size() - 1];
return 0;
}