This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz size()
#define yes "YES"
#define no "NO"
#define IOI ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pf push_front
#define pb push_back
#define S second
#define F first
using namespace std;
const int N = 200 + 5;
const int NN = 1e5;
const int mod = (1e9 + 7);
const int inf = 1e18;
int n, pref[N], a[N], dp[N][NN + 5];
void legenda_ne_umret() {
cin>>n;
for (int i = 1; i <= n; i++){
cin>>a[i];
pref[i] = pref[i - 1] + a[i];
}
dp[0][0]= 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= NN; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++){
for (int j = NN; j >= 1; j--){
if (a[i] == j) dp[i][j] = i;
dp[i][j] = max(dp[i][j],dp[i - 1][j]);
// cout << dp[i][j] << '\n';
if (j + a[i] <= NN) dp[i][j + a[i]] = max(dp[i][j+a[i]],dp[i - 1][j]);
}
}
vector <int> ans;
for (int len = 1; len <= n; len++){
bool can = 1;
for (int i = len; i <= n; i++){
int sum = pref[i] - pref[i - len];
if (sum % 2 == 1 || dp[i][sum / 2] < i - len + 1) {
can = 0;
break;
}
}
if (can) ans.pb(len);
}
cout << ans.sz << ' ';
for (int i : ans) cout << i << ' ';
}
signed main() {
IOI;
// freopen("maze.in", "r", stdin);
// freopen("maze.out", "w", stdout);
/////////////////////////////////////////////
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case " << i << ":\n";
legenda_ne_umret();
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |