比赛 EYOI暨SBOI暑假快乐赛6th 评测结果 AAAAATTEEE
题目名称 Count 1s 最终得分 50
用户昵称 cb 运行时间 2.936 s
代码语言 C++ 内存使用 4.35 MiB
提交时间 2022-06-30 10:38:50
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, a[100005];
  4.  
  5. bool f[100005] = {0};
  6.  
  7. int main () {
  8. freopen ("count1s.in", "r", stdin);
  9. freopen ("count1s.out", "w", stdout);
  10. scanf ("%d", &n);
  11. int cnt = 0;
  12. for (int q = 1; q <= n; ++q) {
  13. scanf ("%d", &a[q]);
  14. if (a[q] == 1) cnt ++;
  15. }
  16. f[cnt] = true;
  17. int x0, x1;
  18. for (int q = 1; q <= n; ++q) {
  19. x0 = 0; x1 = 0;
  20. for (int w = q;w <= n; ++w) {
  21. if (a[w] == 0) x0 ++;
  22. else x1 ++;
  23. f[cnt - x1 + x0] = true;
  24. }
  25. }
  26. int ans = 0;
  27. for (int q = 0; q <= n; ++q) {
  28. if (f[q]) ans ++;
  29. }
  30. printf ("%d\n", ans);
  31. return 0;
  32. }
  33.