結果
問題 | No.2617 容量3のナップザック |
ユーザー | shobonvip |
提出日時 | 2024-01-26 22:17:56 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,772 bytes |
コンパイル時間 | 5,336 ms |
コンパイル使用メモリ | 268,560 KB |
実行使用メモリ | 52,344 KB |
最終ジャッジ日時 | 2024-09-28 08:21:29 |
合計ジャッジ時間 | 8,919 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | RE | - |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 130 ms
38,680 KB |
testcase_13 | AC | 147 ms
46,628 KB |
testcase_14 | AC | 131 ms
37,352 KB |
testcase_15 | AC | 97 ms
30,872 KB |
testcase_16 | AC | 106 ms
27,996 KB |
testcase_17 | AC | 119 ms
35,808 KB |
testcase_18 | AC | 117 ms
36,280 KB |
testcase_19 | AC | 21 ms
9,076 KB |
testcase_20 | AC | 130 ms
43,676 KB |
testcase_21 | AC | 66 ms
20,776 KB |
testcase_22 | AC | 146 ms
46,676 KB |
testcase_23 | AC | 154 ms
46,332 KB |
testcase_24 | AC | 8 ms
6,944 KB |
testcase_25 | AC | 91 ms
30,012 KB |
testcase_26 | AC | 112 ms
29,836 KB |
testcase_27 | AC | 56 ms
17,516 KB |
testcase_28 | AC | 7 ms
6,940 KB |
testcase_29 | AC | 55 ms
19,000 KB |
testcase_30 | AC | 139 ms
44,200 KB |
testcase_31 | AC | 118 ms
35,092 KB |
testcase_32 | AC | 148 ms
51,924 KB |
testcase_33 | AC | 170 ms
52,344 KB |
testcase_34 | AC | 177 ms
51,052 KB |
testcase_35 | AC | 165 ms
51,280 KB |
testcase_36 | AC | 201 ms
51,300 KB |
testcase_37 | AC | 168 ms
50,880 KB |
testcase_38 | AC | 160 ms
50,416 KB |
testcase_39 | AC | 158 ms
50,316 KB |
testcase_40 | AC | 165 ms
50,360 KB |
testcase_41 | AC | 86 ms
50,436 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ int n, k; cin >> n >> k; ll seed; cin >> seed; ll a, b, m; cin >> a >> b >> m; vector<ll> v(n), w(n); vector<ll> f(n * 2); f[0] = seed; for (int i=1; i<n * 2; i++){ f[i] = (a * f[i-1] + b) % m; } for (int i=0; i<n; i++){ w[i] = f[i] % 3 + 1; v[i] = w[i] * f[n + i]; } vector<ll> w1; vector<ll> w2; vector<ll> w3; rep(i,0,n){ if (w[i] == 1){ w1.push_back(v[i]); }else if(w[i] == 2){ w2.push_back(v[i]); }else if(w[i] == 3){ w3.push_back(v[i]); } } sort(w1.begin(), w1.end()); sort(w2.begin(), w2.end()); sort(w3.begin(), w3.end()); reverse(w1.begin(), w1.end()); reverse(w2.begin(), w2.end()); reverse(w3.begin(), w3.end()); int n1 = w1.size(); int n2 = w2.size(); int n3 = w3.size(); vector<ll> rui1(n1 + 1); vector<ll> rui2(n2 + 1); vector<ll> rui3(n3 + 1); rep(i,0,n1) rui1[i+1] = w1[i]; rep(i,0,n2) rui2[i+1] = w2[i]; rep(i,0,n3) rui3[i+1] = w3[i]; rep(i,0,n1) rui1[i+1] += rui1[i]; rep(i,0,n2) rui2[i+1] += rui2[i]; rep(i,0,n3) rui3[i+1] += rui3[i]; vector<int> threes(3); vector<int> ones(3); vector<ll> var(3); ll ans = 0; rep(l,0,k+1){ ll tmp = 0; tmp += rui2[min(l, n2)]; while (ones[l % 3] <= min(l, n1)){ var[l % 3] += w1[ones[l % 3]]; ones[l % 3]++; } while((ones[l % 3] - min(l, n1)) % 3 != 0){ ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; } if(ones[l % 3] > l){ ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; } if(ones[l % 3] > l){ ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; } if(ones[l % 3] > l){ ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; ones[l % 3]--; var[l % 3] -= w1[ones[l % 3]]; } if (threes[l % 3] >= 1){ threes[l % 3]--; var[l % 3] -= w3[threes[l % 3]]; } if (threes[l % 3] >= 1){ threes[l % 3]--; var[l % 3] -= w3[threes[l % 3]]; } if (threes[l % 3] >= 1){ threes[l % 3]--; var[l % 3] -= w3[threes[l % 3]]; } while ((ones[l % 3] < n1 || threes[l%3] < n3) && (ones[l % 3] - min(l, n1) + 2) / 3 + threes[l % 3] < k - l){ if (rui1[min(ones[l%3] + 3, n1)] - rui1[min(ones[l%3], n1)] <= rui3[min(threes[l%3] + 1, n3)] - rui3[min(threes[l%3], n3)]){ var[l%3] += rui3[min(threes[l%3] + 1, n3)] - rui3[min(threes[l%3], n3)]; threes[l%3]++; chmin(threes[l%3], n3); }else{ var[l%3] += rui1[min(ones[l%3] + 3, n1)] - rui1[min(ones[l%3], n1)]; ones[l%3] += 3; chmin(ones[l%3], n1); } } chmax(ans, var[l%3] + tmp); } cout << ans << '\n'; }