結果
| 問題 |
No.3329 Only the Rightest Choice is Right!!!
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2025-11-01 16:48:19 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,194 bytes |
| コンパイル時間 | 3,422 ms |
| コンパイル使用メモリ | 284,172 KB |
| 実行使用メモリ | 73,856 KB |
| 最終ジャッジ日時 | 2025-11-01 16:48:28 |
| 合計ジャッジ時間 | 9,104 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 52 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, w; cin >> n >> w;
vector<int>p(n), q(n);// 価値、重さ
rep(i, n)cin >> p[i];
rep(i, n)cin >> q[i];
vector dp(n + 1, vector<P>(w + 1, { -INF,-INF }));// 価値、index(生)
dp[0][0] = { 0,-1 };
rrep(_i, n)rep(j, w + 1) {
int i = n - 1 - _i;
int ni = i + 1;
if (dp[i][j].first == -INF)continue;
{// use
int nj = j + q[_i];
int nval = dp[i][j].first + p[_i];
P p = { nval,_i };
if (nj <= w) {
chmax(dp[ni][nj], p);
}
}
{//unuse
int nj = j + 0;
int nval = dp[i][j].first + 0;
P p = dp[i][j];
chmax(dp[ni][nj], p);
}
}
int val = 0;
rep(i, w + 1)if (dp[n][i].first > 0)val = i;// chmax(val, dp[n][i].first);
//cout << val << endl;
// cout << dp[n][val].first << " " << dp[n][val].second << endl;
//return 0;
int idx = n;
vector<int>ans;
//cout << dp[4][5].first << " " << dp[4][5].second << endl;
//cout << dp[1][3].first << " " << dp[1][3].second << endl;
//cout << dp[0][0].first << " " << dp[0][0].second << endl;
auto[f, s] = dp[n][val];
while (f) {
ans.push_back(s);
//cout << s << endl;
int ff = n - s;//pre->index
val -= q[s];
//cout << ff << "_" << val << endl;
auto[nf, ns] = dp[ff][val];
f = nf;
s = ns;
}
cout << ans.size() << endl;
for (auto e : ans)cout << e + 1 << " ";
cout << endl;
return 0;
}
kwm_t