Submission #1128205

#TimeUsernameProblemLanguageResultExecution timeMemory
1128205rasbery303Kpart (eJOI21_kpart)C++20
10 / 100
2095 ms448 KiB
#include <iostream> #include <vector> using namespace std; const int N = 1001; int a[N]; vector<bool> dp; vector<int> pack; void solve(){ int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; vector<int> pref(n+1, 0); for (int i = 1; i <= n; ++i) pref[i] = pref[i-1] + a[i]; vector<int> ans; for (int len = 2; len <= n; ++len){ bool add = true; bool in = false; for (int i = 1; i <= n-len+1 && add == true; ++i){ int sum = pref[i+len-1] - pref[i-1]; if (sum%2) continue; in = true; pack.assign(len+1, 0); for (int j = i; j <= i+len-1; ++j) pack[j-i+1] = a[j]; dp.assign(sum+1, false); dp[0] = true; for (int j = 1; j <= len; ++j) for (int val = sum; val >= pack[j]; --val) dp[val] = dp[val] | dp[val-pack[j]]; if (dp[sum/2] == 0) add = false; } if (add && in) ans.push_back(len); } cout << ans.size() << ' '; for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " \n"[i==ans.size()-1]; } int main(){ ios::sync_with_stdio(false); //cin.tie(NULL); int tt; cin >> tt; while(tt--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...