結果
問題 | No.1163 I want to be a high achiever |
ユーザー |
![]() |
提出日時 | 2021-01-27 12:49:34 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,600 bytes |
コンパイル時間 | 2,368 ms |
コンパイル使用メモリ | 213,812 KB |
実行使用メモリ | 214,304 KB |
最終ジャッジ日時 | 2024-06-24 11:19:04 |
合計ジャッジ時間 | 6,031 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
13,756 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 3 ms
6,944 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; struct uns_t {} uns; template <typename Element, typename Head, typename ...Args> auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template <typename Element, typename Head, typename ...Args> auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int main() { constexpr int64_t inf = INT64_MAX / 4; int n, x; cin >> n >> x; auto a = vec<int>(uns, n); auto b = vec<int>(uns, n); for (auto &e : a) cin >> e; for (auto &e : b) cin >> e; int sum = accumulate(begin(a), end(a), 0); auto dp1 = vec(-inf, n + 1, sum + 1); auto dp2 = vec(-inf, n + 1, sum + 1); dp2[0][0] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j <= n; ++j) { for (int k = 0; k <= sum; ++k) { dp1[j][k] = dp2[j][k]; } } for (int j = 1; j <= n; ++j) { for (int k = 0; k <= sum; ++k) { dp1[j][k] = max(dp1[j][k], dp2[j - 1][max(0, k - a[i])] + b[i]); } } swap(dp1, dp2); } int64_t ans = inf, all = accumulate(begin(b), end(b), 0); for (int i = 1; i <= n; ++i) { if (sum < x * i) continue; ans = min(ans, all - dp2[i][x * i]); } if (ans != inf) { cout << ans << endl; } else { cout << -1 << endl; } }