結果
問題 | No.2617 容量3のナップザック |
ユーザー | shobonvip |
提出日時 | 2024-01-26 22:15:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,502 bytes |
コンパイル時間 | 4,824 ms |
コンパイル使用メモリ | 267,392 KB |
実行使用メモリ | 53,004 KB |
最終ジャッジ日時 | 2024-09-28 08:19:54 |
合計ジャッジ時間 | 8,728 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | RE | - |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 100 ms
27,996 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 19 ms
9,080 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 8 ms
6,944 KB |
testcase_25 | AC | 87 ms
29,560 KB |
testcase_26 | AC | 110 ms
29,844 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 53 ms
20,228 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 185 ms
50,700 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 154 ms
50,352 KB |
testcase_40 | WA | - |
testcase_41 | AC | 75 ms
50,248 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 (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'; }