結果
問題 | No.783 門松計画 |
ユーザー |
|
提出日時 | 2019-01-11 22:50:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 769 ms / 2,000 ms |
コード長 | 2,680 bytes |
コンパイル時間 | 2,703 ms |
コンパイル使用メモリ | 209,020 KB |
最終ジャッジ日時 | 2025-01-06 20:24:26 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>#define show(x) std::cerr << #x << " = " << (x) << std::endlusing ll = long long;using ld = long double;constexpr ll MOD = 1000000007LL;template <typename T>constexpr T INF() { return std::numeric_limits<T>::max() / 16; }std::mt19937 mt{std::random_device{}()};template <typename T>std::vector<T> Vec(const std::size_t n, T v) { return std::vector<T>(n, v); }template <class... Args>auto Vec(const std::size_t n, Args... args) { return std::vector<decltype(Vec(args...))>(n, Vec(args...)); }template <typename T, typename A>std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v){os << "[";for (const auto& p : v) { os << p << ","; }return (os << "]\n");}int main(){int N, C;std::cin >> N >> C;std::vector<int> L(N), W(N);for (int i = 0; i < N; i++) { std::cin >> L[i]; }for (int i = 0; i < N; i++) { std::cin >> W[i]; }auto dp = Vec(N, N, 51, 0);for (int i = 0; i < N; i++) {for (int j = 0; j < N; j++) {for (int k = 0; k < N; k++) {if (L[i] > L[j] and L[j] < L[k] and L[i] != L[k] and W[i] + W[j] + W[k] <= C) { dp[j][k][W[i] + W[j] + W[k]] = std::max(dp[j][k][W[i]+ W[j] + W[k]], L[i] + L[j] + L[k]); }if (L[i] < L[j] and L[j] > L[k] and L[i] != L[k] and W[i] + W[j] + W[k] <= C) { dp[j][k][W[i] + W[j] + W[k]] = std::max(dp[j][k][W[i]+ W[j] + W[k]], L[i] + L[j] + L[k]); }}}}for (int i = 0; i <= C; i++) {auto tmp = dp;for (int pp = 0; pp < N; pp++) {for (int p = 0; p < N; p++) {for (int c = 0; c <= C; c++) {if (dp[pp][p][c] == 0) { continue; }if (L[pp] > L[p]) {for (int n = 0; n < N; n++) {if (L[p] >= L[n] or L[pp] == L[n] or c + W[n] > C) { continue; }tmp[p][n][c + W[n]] = std::max(tmp[p][n][c + W[n]], dp[pp][p][c] + L[n]);}} else if (L[pp] < L[p]) {for (int n = 0; n < N; n++) {if (L[p] <= L[n] or L[pp] == L[n] or c + W[n] > C) { continue; }tmp[p][n][c + W[n]] = std::max(tmp[p][n][c + W[n]], dp[pp][p][c] + L[n]);}}}}dp = tmp;}}int ans = 0;for (int i = 0; i < N; i++) {for (int j = 0; j < N; j++) {for (int c = 0; c <= C; c++) { ans = std::max(ans, dp[i][j][c]); }}}std::cout << ans << std::endl;return 0;}