Submission #344247

# Submission time Handle Problem Language Result Execution time Memory
344247 2021-01-05T10:18:05 Z Enkhmunkh Bootfall (IZhO17_bootfall) C++14
13 / 100
1000 ms 492 KB
#include <bits/stdc++.h>
using namespace std;
bool check(int sum, vector<int>v, int n) {
    if(sum % 2) {
        return 0;
    }
    sum /= 2;
    vector<bool> dp(sum + 1, 0);
    dp[0] = 1;
    for(int i = 0; i < n; i++) {
        for(int j = sum; j >= v[i]; j--) {
            if(dp[j - v[i]]) dp[j] = 1;
        }
    }
    if (dp[sum]) {
        return 1;
    }else {
        return 0;
    }
}
int main () {
    int n;
    cin >> n;
    vector<int> arr;
    int sum = 0;
    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        arr.push_back(tmp);
        sum+=tmp;
    }
    vector<int> val;
    for (int i = 1; i <= sum; i++) {
        vector<int> cp(arr);
        sum+=i;
        cp.push_back(i);
        int b = 0;
        for (int j = 0; j < n+1; j++) {
            int tmp = cp[j];
            sum-=tmp;
            cp.erase(cp.begin()+j);
            if (check(sum, cp, n)) {
                b++;
            }
            cp.insert(cp.begin() + j, tmp);
            sum+=tmp;
        }
        if (b == n+1) {
            val.push_back(i);
        }
        cp.pop_back();
        sum-=i;
    }
    cout << val.size() << "\n";
    for (int i = 0; i < val.size(); i++) {
        cout << val[i] << " ";
    }
    cout << "\n";
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < val.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 79 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 191 ms 364 KB Output is correct
9 Correct 19 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 79 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 191 ms 364 KB Output is correct
9 Correct 19 ms 364 KB Output is correct
10 Correct 131 ms 368 KB Output is correct
11 Correct 46 ms 364 KB Output is correct
12 Correct 66 ms 368 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 53 ms 492 KB Output is correct
15 Correct 30 ms 492 KB Output is correct
16 Correct 41 ms 368 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 27 ms 364 KB Output is correct
19 Correct 23 ms 492 KB Output is correct
20 Correct 169 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 79 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 191 ms 364 KB Output is correct
9 Correct 19 ms 364 KB Output is correct
10 Correct 131 ms 368 KB Output is correct
11 Correct 46 ms 364 KB Output is correct
12 Correct 66 ms 368 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 53 ms 492 KB Output is correct
15 Correct 30 ms 492 KB Output is correct
16 Correct 41 ms 368 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 27 ms 364 KB Output is correct
19 Correct 23 ms 492 KB Output is correct
20 Correct 169 ms 492 KB Output is correct
21 Execution timed out 1085 ms 364 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 79 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 191 ms 364 KB Output is correct
9 Correct 19 ms 364 KB Output is correct
10 Correct 131 ms 368 KB Output is correct
11 Correct 46 ms 364 KB Output is correct
12 Correct 66 ms 368 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 53 ms 492 KB Output is correct
15 Correct 30 ms 492 KB Output is correct
16 Correct 41 ms 368 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 27 ms 364 KB Output is correct
19 Correct 23 ms 492 KB Output is correct
20 Correct 169 ms 492 KB Output is correct
21 Execution timed out 1085 ms 364 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 79 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 191 ms 364 KB Output is correct
9 Correct 19 ms 364 KB Output is correct
10 Correct 131 ms 368 KB Output is correct
11 Correct 46 ms 364 KB Output is correct
12 Correct 66 ms 368 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 53 ms 492 KB Output is correct
15 Correct 30 ms 492 KB Output is correct
16 Correct 41 ms 368 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 27 ms 364 KB Output is correct
19 Correct 23 ms 492 KB Output is correct
20 Correct 169 ms 492 KB Output is correct
21 Execution timed out 1085 ms 364 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 79 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 191 ms 364 KB Output is correct
9 Correct 19 ms 364 KB Output is correct
10 Correct 131 ms 368 KB Output is correct
11 Correct 46 ms 364 KB Output is correct
12 Correct 66 ms 368 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 53 ms 492 KB Output is correct
15 Correct 30 ms 492 KB Output is correct
16 Correct 41 ms 368 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 27 ms 364 KB Output is correct
19 Correct 23 ms 492 KB Output is correct
20 Correct 169 ms 492 KB Output is correct
21 Execution timed out 1085 ms 364 KB Time limit exceeded
22 Halted 0 ms 0 KB -