結果
問題 | No.2617 容量3のナップザック |
ユーザー | SSRS |
提出日時 | 2024-01-26 22:37:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 213 ms / 2,000 ms |
コード長 | 1,893 bytes |
コンパイル時間 | 2,207 ms |
コンパイル使用メモリ | 211,352 KB |
実行使用メモリ | 46,640 KB |
最終ジャッジ日時 | 2024-09-28 08:35:44 |
合計ジャッジ時間 | 6,926 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 133 ms
35,764 KB |
testcase_13 | AC | 142 ms
41,628 KB |
testcase_14 | AC | 125 ms
34,288 KB |
testcase_15 | AC | 92 ms
28,576 KB |
testcase_16 | AC | 107 ms
26,068 KB |
testcase_17 | AC | 113 ms
33,232 KB |
testcase_18 | AC | 112 ms
33,420 KB |
testcase_19 | AC | 23 ms
8,480 KB |
testcase_20 | AC | 126 ms
37,796 KB |
testcase_21 | AC | 62 ms
19,116 KB |
testcase_22 | AC | 144 ms
42,504 KB |
testcase_23 | AC | 151 ms
41,572 KB |
testcase_24 | AC | 9 ms
5,376 KB |
testcase_25 | AC | 100 ms
26,820 KB |
testcase_26 | AC | 117 ms
27,404 KB |
testcase_27 | AC | 50 ms
16,108 KB |
testcase_28 | AC | 7 ms
5,376 KB |
testcase_29 | AC | 56 ms
17,680 KB |
testcase_30 | AC | 131 ms
39,092 KB |
testcase_31 | AC | 116 ms
32,316 KB |
testcase_32 | AC | 153 ms
46,384 KB |
testcase_33 | AC | 169 ms
46,264 KB |
testcase_34 | AC | 169 ms
46,400 KB |
testcase_35 | AC | 163 ms
46,640 KB |
testcase_36 | AC | 213 ms
46,392 KB |
testcase_37 | AC | 170 ms
46,388 KB |
testcase_38 | AC | 157 ms
46,264 KB |
testcase_39 | AC | 191 ms
46,248 KB |
testcase_40 | AC | 171 ms
46,388 KB |
testcase_41 | AC | 94 ms
46,244 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N, K; int seed, a, b, m; cin >> N >> K >> seed >> a >> b >> m; vector<long long> f(N * 2); f[0] = seed; for (int i = 1; i < N * 2; i++){ f[i] = (a * f[i - 1] + b) % m; } vector<int> w(N); vector<long long> v(N); for (int i = 0; i < N; i++){ w[i] = f[i] % 3 + 1; v[i] = w[i] * f[N + i]; } vector<vector<long long>> V(3); for (int i = 0; i < N; i++){ V[w[i] - 1].push_back(v[i]); } for (int i = 0; i < 3; i++){ sort(V[i].begin(), V[i].end(), greater<long long>()); } vector<vector<long long>> S(3); for (int i = 0; i < 3; i++){ int cnt = V[i].size(); S[i].resize(cnt + 1); S[i][0] = 0; for (int j = 0; j < cnt; j++){ S[i][j + 1] = S[i][j] + V[i][j]; } } auto get = [&](int i, int j) -> long long { return S[i][min(j, (int) S[i].size() - 1)]; }; auto solve1 = [&](int a, int b, int c){ return get(0, a * 3 + b) + get(1, b) + get(2, c); }; auto solve2 = [&](int c){ int L = 0, R = K - c; long long ans = 0; while (R - L > 2){ int ml = (L * 2 + R) / 3; int mr = (L + R * 2) / 3; long long s1 = solve1(ml, K - c - ml, c); long long s2 = solve1(mr, K - c - mr, c); ans = max(ans, s1); ans = max(ans, s2); if (s1 < s2){ L = ml; } else { R = mr; } } for (int i = 0; i <= K-c; i++){ ans = max(ans, solve1(i, K - c - i, c)); } return ans; }; int L = 0, R = K; long long ans = 0; while (R - L > 2){ int ml = (L * 2 + R) / 3; int mr = (L + R * 2) / 3; long long s1 = solve2(ml); long long s2 = solve2(mr); ans = max(ans, s1); ans = max(ans, s2); if (s1 < s2){ L = ml; } else { R = mr; } } for (int i = L; i <= R; i++){ ans = max(ans, solve2(i)); } cout << ans << endl; }