답안 #682011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682011 2023-01-15T08:31:16 Z boykut Bootfall (IZhO17_bootfall) C++14
0 / 100
1 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 1000;
int dp[MAX*MAX], can[MAX*MAX];
int a[MAX];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int n, sum;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int x = sum; x >= 0; x--) {
      dp[x+a[i]] += dp[x];
    }
  }
  
  if (sum%2 == 1 || dp[sum/2] == 0) {
    return cout << 0, 0;
  }
  
  fill(can, can+sum+1, 1);
  
  vector<int> ans;
  
  for (int Without = 0; Without < n; Without++) {
    fill(dp, dp+sum+1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
      for (int x = sum; x >= 0; x--) {
        if (i != Without)
          dp[x+a[i]] += dp[x];
      }
    }
    // a[Without] êàìåðà êàðìàï òóðàò
    for (int Tima = 1; Tima <= sum; Tima++) {
      if ((sum-a[Without]+Tima)%2 == 1 || dp[(sum-a[Without]+Tima)/2] == 0) {
        can[Tima] = 0;
      }
    }
  }
  
  for (int Tima = 1; Tima <= sum; Tima++) {
    if (can[Tima] == 1) {
      ans.push_back(Tima);
    }
  }
  
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int i = 0; i < ans.size(); i++) {
      |                   ~~^~~~~~~~~~~~
bootfall.cpp:52:27: warning: 'sum' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |   for (int Tima = 1; Tima <= sum; Tima++) {
      |                      ~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -