답안 #156211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156211 2019-10-04T12:10:51 Z theboatman Bootfall (IZhO17_bootfall) C++17
13 / 100
1000 ms 36916 KB
#include <bits/stdc++.h>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;

int main() {
    cin.tie(0);
    ios :: sync_with_stdio(0);

    int n;
    cin >> n;

    int sum = 0;
    vector <int> a(n + 1);

    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    vector <vector <int> > dp_pref(n + 1, vector <int> (sum * 2 + 1));
    dp_pref[0][sum] = 1;

    vector <set <int> > pref(n + 1);
    pref[0].insert(sum);

    for(int i = 1; i <= n; i++) {
        for(int bal = 0; bal <= sum * 2; bal++) {
            if (dp_pref[i - 1][bal]) {
                dp_pref[i][bal + a[i]] = 1;
                dp_pref[i][bal - a[i]] = 1;
            }
        }

        for(int bal = 0; bal <= sum * 2; bal++) {
            if (dp_pref[i][bal]) {
                pref[i].insert(bal);
            }
        }
    }

    vector <vector <int> > dp_suff(n + 2, vector <int> (sum * 2 + 1));
    dp_suff[n + 1][sum] = 1;

    vector <set <int> > suff(n + 2);
    suff[n + 1].insert(sum);

    for(int i = n; i > 0; i--) {
        for(int bal = 0; bal <= sum * 2; bal++) {
            if (dp_suff[i + 1][bal]) {
                dp_suff[i][bal + a[i]] = 1;
                dp_suff[i][bal - a[i]] = 1;
            }
        }

        for(int bal = 0; bal <= sum * 2; bal++) {
            if (dp_suff[i][bal]) {
                suff[i].insert(bal);
            }
        }
    }

    vector <int> ans;
    for(int power = 1; power <= sum; power++) {
        int ok = 0;

        if (!dp_pref[n][sum]) {
            ok = -1;
        }

        for(int i = 1; i <= n; i++) {
            for(auto it : pref[i - 1]) {
                //cout << it << endl;
                if (suff[i + 1].find(2 * sum - it - power) != suff[i + 1].end()) {
                    ok++;
                    break;
                }
            }

            if (ok != i) {
                break;
            }
        }

        if (ok == n) {
            ans.push_back(power);
        }
    }

    cout << ans.size() << "\n";
    for(auto i : ans) {
        cout << i << " ";
    }
    return 0;
}
/*
x + power + y - sum == 0

y == sum - x - power

1001
999
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 5 ms 888 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 5 ms 888 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 5 ms 888 KB Output is correct
15 Correct 4 ms 764 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 5 ms 888 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 5 ms 888 KB Output is correct
15 Correct 4 ms 764 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 329 ms 12964 KB Output is correct
22 Correct 473 ms 16248 KB Output is correct
23 Correct 137 ms 7544 KB Output is correct
24 Correct 883 ms 27720 KB Output is correct
25 Execution timed out 1067 ms 36916 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 5 ms 888 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 5 ms 888 KB Output is correct
15 Correct 4 ms 764 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 329 ms 12964 KB Output is correct
22 Correct 473 ms 16248 KB Output is correct
23 Correct 137 ms 7544 KB Output is correct
24 Correct 883 ms 27720 KB Output is correct
25 Execution timed out 1067 ms 36916 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 5 ms 888 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 5 ms 888 KB Output is correct
15 Correct 4 ms 764 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 329 ms 12964 KB Output is correct
22 Correct 473 ms 16248 KB Output is correct
23 Correct 137 ms 7544 KB Output is correct
24 Correct 883 ms 27720 KB Output is correct
25 Execution timed out 1067 ms 36916 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 5 ms 888 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 5 ms 888 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 5 ms 888 KB Output is correct
15 Correct 4 ms 764 KB Output is correct
16 Correct 4 ms 760 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 329 ms 12964 KB Output is correct
22 Correct 473 ms 16248 KB Output is correct
23 Correct 137 ms 7544 KB Output is correct
24 Correct 883 ms 27720 KB Output is correct
25 Execution timed out 1067 ms 36916 KB Time limit exceeded
26 Halted 0 ms 0 KB -