답안 #344238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344238 2021-01-05T10:09:21 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;
        sum+=i;
        for (int j = 0; j < n; j++) {
            cp.push_back(arr[j]);
        }
        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:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0; i < val.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 82 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 190 ms 364 KB Output is correct
9 Correct 21 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 82 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 190 ms 364 KB Output is correct
9 Correct 21 ms 364 KB Output is correct
10 Correct 122 ms 364 KB Output is correct
11 Correct 48 ms 492 KB Output is correct
12 Correct 65 ms 364 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 51 ms 364 KB Output is correct
15 Correct 27 ms 364 KB Output is correct
16 Correct 41 ms 384 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 31 ms 364 KB Output is correct
19 Correct 22 ms 364 KB Output is correct
20 Correct 164 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 82 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 190 ms 364 KB Output is correct
9 Correct 21 ms 364 KB Output is correct
10 Correct 122 ms 364 KB Output is correct
11 Correct 48 ms 492 KB Output is correct
12 Correct 65 ms 364 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 51 ms 364 KB Output is correct
15 Correct 27 ms 364 KB Output is correct
16 Correct 41 ms 384 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 31 ms 364 KB Output is correct
19 Correct 22 ms 364 KB Output is correct
20 Correct 164 ms 364 KB Output is correct
21 Execution timed out 1082 ms 372 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 82 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 190 ms 364 KB Output is correct
9 Correct 21 ms 364 KB Output is correct
10 Correct 122 ms 364 KB Output is correct
11 Correct 48 ms 492 KB Output is correct
12 Correct 65 ms 364 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 51 ms 364 KB Output is correct
15 Correct 27 ms 364 KB Output is correct
16 Correct 41 ms 384 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 31 ms 364 KB Output is correct
19 Correct 22 ms 364 KB Output is correct
20 Correct 164 ms 364 KB Output is correct
21 Execution timed out 1082 ms 372 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 82 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 190 ms 364 KB Output is correct
9 Correct 21 ms 364 KB Output is correct
10 Correct 122 ms 364 KB Output is correct
11 Correct 48 ms 492 KB Output is correct
12 Correct 65 ms 364 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 51 ms 364 KB Output is correct
15 Correct 27 ms 364 KB Output is correct
16 Correct 41 ms 384 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 31 ms 364 KB Output is correct
19 Correct 22 ms 364 KB Output is correct
20 Correct 164 ms 364 KB Output is correct
21 Execution timed out 1082 ms 372 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 82 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 190 ms 364 KB Output is correct
9 Correct 21 ms 364 KB Output is correct
10 Correct 122 ms 364 KB Output is correct
11 Correct 48 ms 492 KB Output is correct
12 Correct 65 ms 364 KB Output is correct
13 Correct 31 ms 364 KB Output is correct
14 Correct 51 ms 364 KB Output is correct
15 Correct 27 ms 364 KB Output is correct
16 Correct 41 ms 384 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 31 ms 364 KB Output is correct
19 Correct 22 ms 364 KB Output is correct
20 Correct 164 ms 364 KB Output is correct
21 Execution timed out 1082 ms 372 KB Time limit exceeded
22 Halted 0 ms 0 KB -