Submission #914572

#TimeUsernameProblemLanguageResultExecution timeMemory
914572efedmrlrKpart (eJOI21_kpart)C++17
30 / 100
2039 ms1168 KiB
// #pragma GCC optimize("O3,Ofast,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> using namespace std; #define lli long long int #define MP make_pair #define pb push_back #define REP(i,n) for(int i = 0; (i) < (n); (i)++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const double EPS = 0.00001; const int INF = 1e9+500; const int N = 1e3+5; const int MX = 1e5 + 5; const int ALPH = 26; const int LGN = 25; constexpr int MOD = 1e9+7; int n,m,q; inline void solve() { cin>>n; vector<int> dp(MX, 0); vector<int> pref(n + 3, 0); vector<int> valid(n + 3, 1); vector<int> a(n + 3, 0); for(int i = 1; i<=n; i++) { cin>>a[i]; pref[i] = a[i] + pref[i - 1]; } dp[0] = INF; for(int i = 1; i<=n; i++) { for(int v = MX - 1; v>=0; v--) { if(v - a[i] < 0) continue; dp[v] = max(dp[v], min(dp[v - a[i]] , i)); } for(int j = 1; j<=i; j++) { int len = i - j + 1; int val = pref[i] - pref[j - 1]; if((val & 1) || (dp[val / 2] < j)) { valid[len] = 0; } } } int cnt = 0; for(int i = 1; i<=n; i++) cnt += valid[i]; cout<<cnt<<" "; for(int i = 1; i<=n; i++) { if(valid[i]) cout<<i<<" "; } cout<<"\n"; } signed main() { fastio(); int test = 1; cin>>test; while(test--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...