#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int ll
#define left (h<<1),l,((l+r)>>1)
#define right ((h<<1)|1),((l+r)>>1) + 1,r
using namespace std;
const int N = 1005,M = 50000;
int a[N],dp[N][M+5],p[N];
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>a[i],p[i] = p[i - 1] + a[i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 50000; j++)
dp[i][j] = -1;
dp[0][0] = 0;
for (int i = 1; i <= n; i++){
for (int j = 50000; j >= 1; j--){
if (a[i] == j) dp[i][j] = i;
dp[i][j] = max(dp[i][j],dp[i - 1][j]);
if (j + a[i] <= 50000)
dp[i][j + a[i]] = max(dp[i][j+a[i]],dp[i - 1][j]);
}
}
vector <int> ans; ans.clear();
for (int i = 1; i <= n; i++){
bool check = 1;
for (int j = i; j <= n; j++){
int s = p[j] - p[j - i];
if (s%2 || dp[j][s/2] < j - i + 1) {check = 0; break;}
}
if (check) ans.pb(i);
}
cout<<ans.size()<<" ";
for (int x: ans)
cout<<x<<" ";
cout<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
12068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
26544 KB |
Output is correct |
2 |
Correct |
303 ms |
46104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
567 ms |
100500 KB |
Output is correct |
2 |
Correct |
1014 ms |
150348 KB |
Output is correct |
3 |
Correct |
1000 ms |
169920 KB |
Output is correct |
4 |
Correct |
1423 ms |
221100 KB |
Output is correct |
5 |
Execution timed out |
2037 ms |
342468 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |