Submission #681994

# Submission time Handle Problem Language Result Execution time Memory
681994 2023-01-15T06:41:18 Z boykut Bootfall (IZhO17_bootfall) C++14
13 / 100
1000 ms 352 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 555;
int dp[MAX*MAX], cant[MAX*MAX];
int a[MAX];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int n;
  cin >> n;
  
  dp[0] = 1;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int x = sum; x >= 0; x--) {
      dp[x+a[i]] += dp[x];
    }
    sum += a[i];
  }
  
  if (sum%2 == 1 || dp[sum/2] == 0) {
    return cout << 0, 0;
  }
  
  vector<int> ans;
  for (int Tima = 0; Tima <= sum; Tima++) {
    
    for (int Without = 0; Without < n; Without++) {
      
      fill(dp, dp+sum+1, 0);
      dp[0] = 1;
      for (int i = 0; i < n; i++) {
        if (i == Without) {
          swap(a[i], Tima);
        }
        for (int x = sum-a[i]; x >= 0; x--) {
          dp[x + a[i]] += dp[x];
        }
        if (i == Without) {
          swap(a[i], Tima);
        }
      }
      if ((sum+Tima-a[Without])%2 == 1 || dp[(sum+Tima-a[Without])/2] == 0) {
        cant[Tima] = 1;
        break;
      } 
    }
    
  }
  
  for (int Tima = 0; Tima <= sum; Tima++) {
    if (cant[Tima] == 0)
      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:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for (int i = 0; i < ans.size(); i++) {
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 16 ms 352 KB Output is correct
15 Correct 10 ms 340 KB Output is correct
16 Correct 14 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 7 ms 340 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 16 ms 352 KB Output is correct
15 Correct 10 ms 340 KB Output is correct
16 Correct 14 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 7 ms 340 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
21 Execution timed out 1089 ms 340 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 16 ms 352 KB Output is correct
15 Correct 10 ms 340 KB Output is correct
16 Correct 14 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 7 ms 340 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
21 Execution timed out 1089 ms 340 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 16 ms 352 KB Output is correct
15 Correct 10 ms 340 KB Output is correct
16 Correct 14 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 7 ms 340 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
21 Execution timed out 1089 ms 340 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 31 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 16 ms 352 KB Output is correct
15 Correct 10 ms 340 KB Output is correct
16 Correct 14 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 7 ms 340 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
21 Execution timed out 1089 ms 340 KB Time limit exceeded
22 Halted 0 ms 0 KB -