# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
537600 | dantoh000 | Kpart (eJOI21_kpart) | C++14 | 1757 ms | 852 KiB |
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>
using namespace std;
map<int,int> ct;
int tc;
int n;
int can[1005];
int a[1005];
int lst[100005];
int p[1005];
int main(){
scanf("%d",&tc);
while (tc--){
scanf("%d",&n);
for (int i = 1; i <= n; i++){
scanf("%d",&a[i]);
p[i] = a[i] + p[i-1];
}
lst[0] = 0;
for (int i = 1; i <= n; i++) can[i] = 1;
for (int i = 1; i <= 100000; i++) lst[i] = -1;
for (int i = 1; i <= n; i++){
for (int j = 100000-a[i]; j >= 0; j--){
if (lst[j] == -1) continue;
lst[j+a[i]] = max(lst[j], lst[j+a[i]]);
}
for (int k = 1; k <= i; k++){
int s = p[i]-p[i-k];
if (s % 2 == 1 || lst[s/2] < i-k+1){
can[k] = false;
}
}
lst[0] = i;
}
int ct = 0;
for (int i = 0; i <= n; i++) {
ct += can[i];
}
printf("%d ",ct);
for (int i = 0; i <= n; i++) {
if (can[i]) printf("%d ",i);
}
printf("\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |