# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1032029 |
2024-07-23T10:22:34 Z |
tvladm2009 |
Kpart (eJOI21_kpart) |
C++17 |
|
449 ms |
944 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 7;
const int SUM = 1e5 + 7;
int a[N], dp[SUM], pref[N];
bool ok[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
ok[i] = 1;
}
for (int i = 0; i <= pref[n] / 2; ++i) {
dp[i] = 0;
}
for (int i = 1; i <= n; ++i) {
dp[0] = i;
for (int j = pref[n] / 2 - a[i]; j >= 0; --j) {
dp[j + a[i]] = max(dp[j + a[i]], dp[j]);
}
for (int j = 1; j <= i; ++j) {
if (dp[(pref[i] - pref[i - j]) / 2] <= i - j || (pref[i] - pref[i - j]) % 2 == 1) {
ok[j] = 0;
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) ans += ok[i];
cout << ans << " ";
for (int i = 1; i <= n; ++i) {
if (ok[i]) cout << i << " ";
}
cout << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
344 KB |
Output is correct |
2 |
Correct |
73 ms |
580 KB |
Output is correct |
3 |
Correct |
80 ms |
584 KB |
Output is correct |
4 |
Correct |
141 ms |
596 KB |
Output is correct |
5 |
Correct |
336 ms |
600 KB |
Output is correct |
6 |
Correct |
449 ms |
656 KB |
Output is correct |
7 |
Correct |
433 ms |
944 KB |
Output is correct |