Submission #914576

#TimeUsernameProblemLanguageResultExecution timeMemory
914576efedmrlrKpart (eJOI21_kpart)C++17
100 / 100
1890 ms1100 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; int dp[MX]; int pref[N]; int valid[N]; int a[N]; inline void solve() { cin>>n; REP(i, MX) { dp[i] = 0; } REP(i, n + 1) { valid[i] = 1; } 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 >> 1] < 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...