結果
問題 | No.2617 容量3のナップザック |
ユーザー | shobonvip |
提出日時 | 2024-01-26 22:20:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,781 bytes |
コンパイル時間 | 4,016 ms |
コンパイル使用メモリ | 267,044 KB |
実行使用メモリ | 50,680 KB |
最終ジャッジ日時 | 2024-09-28 08:23:04 |
合計ジャッジ時間 | 8,906 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | RE | - |
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 | 141 ms
38,688 KB |
testcase_13 | AC | 158 ms
44,968 KB |
testcase_14 | AC | 135 ms
37,360 KB |
testcase_15 | AC | 98 ms
31,000 KB |
testcase_16 | AC | 104 ms
28,120 KB |
testcase_17 | AC | 126 ms
35,812 KB |
testcase_18 | AC | 122 ms
36,272 KB |
testcase_19 | AC | 19 ms
9,076 KB |
testcase_20 | AC | 132 ms
40,780 KB |
testcase_21 | AC | 66 ms
20,644 KB |
testcase_22 | AC | 150 ms
46,072 KB |
testcase_23 | AC | 158 ms
45,168 KB |
testcase_24 | AC | 9 ms
5,376 KB |
testcase_25 | AC | 94 ms
29,148 KB |
testcase_26 | AC | 113 ms
29,708 KB |
testcase_27 | AC | 54 ms
17,392 KB |
testcase_28 | AC | 6 ms
5,376 KB |
testcase_29 | AC | 55 ms
18,984 KB |
testcase_30 | AC | 142 ms
42,612 KB |
testcase_31 | AC | 122 ms
35,084 KB |
testcase_32 | AC | 153 ms
50,300 KB |
testcase_33 | AC | 177 ms
50,296 KB |
testcase_34 | AC | 182 ms
50,372 KB |
testcase_35 | AC | 174 ms
50,680 KB |
testcase_36 | AC | 202 ms
50,304 KB |
testcase_37 | AC | 177 ms
50,424 KB |
testcase_38 | AC | 173 ms
50,424 KB |
testcase_39 | AC | 181 ms
50,284 KB |
testcase_40 | AC | 179 ms
50,300 KB |
testcase_41 | AC | 96 ms
50,328 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(0); vector<ll> w2(0); vector<ll> w3(0); 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'; }