# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073788 | horiaboeriu | Kpart (eJOI21_kpart) | C++17 | 705 ms | 512 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 <stdio.h>
#include <stdlib.h>
#define MAX 50000
#define MAXN 1000
char f[MAXN + 1];
int v[MAXN + 1];
short dp[MAX + 1];//dp[x] este cea mai mare pozitie de pe care incepe un subsir cu suma x
int main()
{
int t1, i1, n, i, sum, x, s, j, nr;
scanf("%d", &t1);
for (i1 = 0; i1 < t1; i1++) {
scanf("%d", &n);
sum = 0;
for (i = 1; i <= n; i++) {
f[i] = 0;
scanf("%d", &v[i]);
sum += v[i];
}
sum = sum / 2 + 1;
for (i = 0; i <= sum; i++) {
dp[i] = 0;
}
//o sa fac dp si o sa iau fiecare secventa din n si ar trebui sa existe un subsir in acea secventa care sa aiba suma cat jumatatea din suma secventei
for (i = 1; i <= n; i++) {
for (x = sum - v[i]; x > 0; x--) {
if (dp[x] > dp[x + v[i]]) {
dp[x + v[i]] = dp[x];
}
}
dp[v[i]] = i;//suma v[i] se poate obtine de pe poz i
s = 0;
for (j = i; j > 0; j--) {
s += v[j];
if (s % 2 > 0 || dp[s / 2] < j) {
f[i - j + 1] = 1;
}
}
}
nr = 0;
for (i = 1; i <= n; i++) {
nr += 1 - f[i];
}
printf("%d ", nr);
for (i = 1; i <= n; i++) {
if (f[i] == 0) {
printf("%d ", i);
}
}
printf("\n");
}
return 0;
}
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... |