// #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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
840 KB |
Output is correct |
2 |
Correct |
214 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
406 ms |
1092 KB |
Output is correct |
2 |
Correct |
729 ms |
848 KB |
Output is correct |
3 |
Correct |
836 ms |
860 KB |
Output is correct |
4 |
Correct |
1012 ms |
860 KB |
Output is correct |
5 |
Correct |
1553 ms |
872 KB |
Output is correct |
6 |
Correct |
1890 ms |
1100 KB |
Output is correct |
7 |
Correct |
1683 ms |
928 KB |
Output is correct |