Submission #1073788

#TimeUsernameProblemLanguageResultExecution timeMemory
1073788horiaboeriuKpart (eJOI21_kpart)C++17
100 / 100
705 ms512 KiB
#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)

Main.cpp: In function 'int main()':
Main.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d", &t1);
      |     ~~~~~^~~~~~~~~~~
Main.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
Main.cpp:17:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |             scanf("%d", &v[i]);
      |             ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...