#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define sz(_v) (int)_v.size()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
int a[1010];
int dp[1001][50001];
int pref[1001];
int n;
void solve() {
cin >> n;
int g = 0, sum = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
g = __gcd(g, a[i]);
}
for(int i = 1; i <= n; ++i) {
a[i] /= g;
sum += a[i];
pref[i] = pref[i - 1] + a[i];
}
for(int i = 1; i <= n; ++i) {
int x = min(pref[i], sum / 2);
for(int j = 1; j <= x; ++j) {
dp[i][j] = dp[i][j - 1];
if(j == a[i]) dp[i][j] = i;
if(j > a[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]]);
}
if(pref[i] <= x) dp[i][pref[i]] = max(dp[i][pref[i]], 1);
}
veci ans;
for(int len = 2; len <= n; ++len) {
bool can = 1;
for(int l = 1; l + len - 1 <= n; ++l) {
int r = l + len - 1;
int s = pref[r] - pref[l - 1];
if(s & 1) {
can = 0;
break;
}
if(dp[r][s / 2] < l) {
can = 0;
break;
}
}
if(can) ans.pb(len);
}
cout << sz(ans) << ' '; for(auto i : ans) cout << i << ' ';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int CNT_TESTS = 1;
cin >> CNT_TESTS;
for(int NUMCASE = 1; NUMCASE <= CNT_TESTS; ++NUMCASE) {
solve();
if(NUMCASE != CNT_TESTS) cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
1476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
138 ms |
11508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |