// #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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
856 KB |
Output is correct |
2 |
Correct |
282 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
547 ms |
964 KB |
Output is correct |
2 |
Correct |
931 ms |
956 KB |
Output is correct |
3 |
Correct |
991 ms |
968 KB |
Output is correct |
4 |
Correct |
1337 ms |
860 KB |
Output is correct |
5 |
Correct |
1982 ms |
916 KB |
Output is correct |
6 |
Execution timed out |
2039 ms |
1168 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |