Submission #1151254

#TimeUsernameProblemLanguageResultExecution timeMemory
1151254andrei_nKpart (eJOI21_kpart)C++20
30 / 100
2095 ms912 KiB
#include <bits/stdc++.h> using namespace std; const int LIMIT = 15000; bitset<LIMIT+5> dp[1005]; int v[1005]; int fr[1005]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin>>T; while(T--) { int n; cin>>n; for(int i=1; i<=n; ++i) { cin>>v[i]; fr[i] = 0; } for(int i=1; i<=n; ++i) { for(int j=0; j<=n-i+1; ++j) dp[j].reset(); dp[0][0] = 1; for(int j=i; j<=n; ++j) { for(int k = 0; k <= LIMIT; ++k) if(dp[j-i][k]) { if(k + v[j] <= LIMIT) dp[j-i+1][k + v[j]] = 1; dp[j-i+1][abs(k - v[j])] = 1; } if(dp[j-i+1][0]) ++fr[j-i+1]; } } vector<int> ok; for(int i=1; i<=n; ++i) if(fr[i] == n - i + 1) ok.push_back(i); cout<<ok.size(); for(auto &i : ok) cout<<' '<<i; cout<<'\n'; } return 0; } /* 2 7 7 3 5 1 3 3 5 6 1 2 3 5 8 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...