# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
537531 |
2022-03-15T07:48:01 Z |
joelau |
Kpart (eJOI21_kpart) |
C++14 |
|
1685 ms |
844 KB |
#include <bits/stdc++.h>
using namespace std;
int T,N,A[1005], sum[1005], dp[2][50005];
bitset<1005> bs;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> T;
while (T--) {
cin >> N;
sum[0] = 0;
for (int i = 1; i <= N; ++i) {
cin >> A[i];
sum[i] = sum[i-1] + A[i];
}
bs.reset();
for (int i = 1; i <= N; ++i) bs[i] = 1;
memset(dp[1],-1,sizeof(dp[1]));
dp[1][0] = 0;
for (int i = 1; i <= N; ++i) {
memset(dp[0],-1,sizeof(dp[0]));
dp[0][0] = dp[0][A[i]] = i;
for (int j = 0; j + A[i] <= sum[i] && j <= sum[N]/2; ++j) dp[0][j] = max(dp[0][j],dp[1][j]), dp[0][j+A[i]] = max(dp[0][j+A[i]],dp[1][j]);
for (int j = 1; j <= i; ++j) {
int total = sum[i] - sum[j-1];
if (total % 2 == 1 || dp[0][total/2] < j) bs[i-j+1] = 0;
}
swap(dp[0],dp[1]);
}
cout << bs.count();
for (int i = 1; i <= N; ++i) if (bs[i]) cout << ' ' << i;
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
724 KB |
Output is correct |
2 |
Correct |
100 ms |
704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
724 KB |
Output is correct |
2 |
Correct |
431 ms |
716 KB |
Output is correct |
3 |
Correct |
461 ms |
728 KB |
Output is correct |
4 |
Correct |
703 ms |
844 KB |
Output is correct |
5 |
Correct |
1263 ms |
732 KB |
Output is correct |
6 |
Correct |
1685 ms |
840 KB |
Output is correct |
7 |
Correct |
1544 ms |
728 KB |
Output is correct |