Submission #897471

# Submission time Handle Problem Language Result Execution time Memory
897471 2024-01-03T07:11:31 Z AI_2512 Bootfall (IZhO17_bootfall) C++17
13 / 100
1000 ms 500 KB
#include <bits/stdc++.h>
 
using namespace std;
bool canPartition(vector<int> nums) {
    int totalSum = 0;
    for (int num : nums) {
        totalSum += num;
    }
    if (totalSum % 2 != 0) {
        return false;
    }

    int targetSum = totalSum / 2;
    int n = nums.size();
    vector<vector<bool>> dp(n + 1, vector<bool>(targetSum + 1, false));
    for (int i = 0; i <= n; ++i) {
        dp[i][0] = true;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= targetSum; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j >= nums[i - 1]) {
                dp[i][j] = dp[i][j] || dp[i - 1][j - nums[i - 1]];
            }
        }
    }
    return dp[n][targetSum];
}

bool can(vector<int> vec){
    for (int i = 0; i< vec.size(); i++){
        vector<int> darr(vec.begin(), vec.end());
        darr.erase(next(darr.begin(), i));
        if (!canPartition(darr)) return false;
    }
    return true;
}

signed main(){
    int n, sum = 0;
    cin >> n;
    vector<int> vec;
    vector<int> res;
    for (int i = 0; i< n; i++){
        int a;
        cin >> a;
        vec.push_back(a);
        sum+=a;
    }

    for (int i = 1; i<= sum; i++){
        vec.push_back(i);
        if (can(vec)){
            res.push_back(i);
        }
        vec.erase(vec.end()-1);
    }
    cout << res.size() << "\n";
    for (int el:res) cout << el << " ";
    return 0;
}

Compilation message

bootfall.cpp: In function 'bool can(std::vector<int>)':
bootfall.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i< vec.size(); i++){
      |                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 65 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 121 ms 424 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 65 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 121 ms 424 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 32 ms 348 KB Output is correct
11 Correct 69 ms 348 KB Output is correct
12 Correct 9 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 77 ms 348 KB Output is correct
15 Correct 47 ms 348 KB Output is correct
16 Correct 69 ms 420 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 40 ms 412 KB Output is correct
19 Correct 31 ms 416 KB Output is correct
20 Correct 34 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 65 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 121 ms 424 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 32 ms 348 KB Output is correct
11 Correct 69 ms 348 KB Output is correct
12 Correct 9 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 77 ms 348 KB Output is correct
15 Correct 47 ms 348 KB Output is correct
16 Correct 69 ms 420 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 40 ms 412 KB Output is correct
19 Correct 31 ms 416 KB Output is correct
20 Correct 34 ms 344 KB Output is correct
21 Execution timed out 1030 ms 500 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 65 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 121 ms 424 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 32 ms 348 KB Output is correct
11 Correct 69 ms 348 KB Output is correct
12 Correct 9 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 77 ms 348 KB Output is correct
15 Correct 47 ms 348 KB Output is correct
16 Correct 69 ms 420 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 40 ms 412 KB Output is correct
19 Correct 31 ms 416 KB Output is correct
20 Correct 34 ms 344 KB Output is correct
21 Execution timed out 1030 ms 500 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 65 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 121 ms 424 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 32 ms 348 KB Output is correct
11 Correct 69 ms 348 KB Output is correct
12 Correct 9 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 77 ms 348 KB Output is correct
15 Correct 47 ms 348 KB Output is correct
16 Correct 69 ms 420 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 40 ms 412 KB Output is correct
19 Correct 31 ms 416 KB Output is correct
20 Correct 34 ms 344 KB Output is correct
21 Execution timed out 1030 ms 500 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 65 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 121 ms 424 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 32 ms 348 KB Output is correct
11 Correct 69 ms 348 KB Output is correct
12 Correct 9 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 77 ms 348 KB Output is correct
15 Correct 47 ms 348 KB Output is correct
16 Correct 69 ms 420 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 40 ms 412 KB Output is correct
19 Correct 31 ms 416 KB Output is correct
20 Correct 34 ms 344 KB Output is correct
21 Execution timed out 1030 ms 500 KB Time limit exceeded
22 Halted 0 ms 0 KB -