Submission #37419

# Submission time Handle Problem Language Result Execution time Memory
37419 2017-12-25T09:12:15 Z HardNut Bootfall (IZhO17_bootfall) C++14
13 / 100
243 ms 132364 KB
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

const int N = 1e5 + 5;

typedef long long ll;

int n, a[205], dp1[205][50005], dp2[205][50005], sum;
vector<int> ans, vec;
int dp[205][50005];
bool us[205][50005];
bool used[50005];

bool is(int s, int v) {
    if (us[v][s])
        return dp[v][s];
    us[v][s] = 1;
    for (int i = 0; i <= s; i++) {
        if ((dp1[v - 1][i] && dp2[v + 1][s - i]) || (dp2[v + 1][i] && dp1[v - 1][s - i])) {
            dp[v][s] = 1;
            return 1;
        }
    }
    dp[v][s] = 0;
    return 0;
}

int main() {
//    freopen("bootfall.in", "r", stdin);
//    freopen("bootfall.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    if (n > 100) {
        cout << "SAd";
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        dp[i][0] = 1;
        cin >> a[i];
        sum += a[i];
    }
    if (sum % 2 == 1) {
        cout << 0;
        return 0;
    }
    bool u = 0;
    dp1[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= sum; j++) {
            if (dp1[i - 1][j]) {
                if (j + a[i] == sum / 2)
                    u = 1;
                dp1[i][j + a[i]] = 1;
                dp1[i][j] = 1;
                dp[i][j + a[i]] = 1;
            }
        }
    }
    if (u == 0) {
        cout << 0;
        return 0;
    }
    if (sum > 5e4) {
        cout << "sdf";
        return 0;
    }
    dp2[n + 1][0] = 1;
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j <= sum; j++) {
            if (dp2[i + 1][j]) {
                dp2[i][j + a[i]] = 1;
                dp2[i][j] = 1;
                dp[i][j + a[i]] = 1;
            }
        }
    }
    for (int i = 0; i <= sum; i++) {
        if (dp1[n - 1][i])
            vec.push_back(i);
    }
    for (int i : vec) {
        int x = abs(i - (sum - a[n] - i));
        bool u = 0;
        for (int j = 1; j <= n; j++) {
            if ((sum - a[j] + x) % 2) {
                u = 1;
                break;
            }
            if (!is((sum - a[j] + x) / 2, j)) {
                u = 1;
                break;
            }
        }
        if (!u) {
            if (!used[x]) {
                ans.push_back(x);
                used[x] = 1;
            }
        }
    }
    cout << ans.size() << "\n";
    for (int i = ans.size() - 1; i >= 0; i--)
        cout << ans[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 132364 KB Output is correct
2 Correct 0 ms 132364 KB Output is correct
3 Correct 0 ms 132364 KB Output is correct
4 Correct 0 ms 132364 KB Output is correct
5 Correct 0 ms 132364 KB Output is correct
6 Correct 0 ms 132364 KB Output is correct
7 Correct 0 ms 132364 KB Output is correct
8 Correct 0 ms 132364 KB Output is correct
9 Correct 0 ms 132364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 132364 KB Output is correct
2 Correct 0 ms 132364 KB Output is correct
3 Correct 0 ms 132364 KB Output is correct
4 Correct 0 ms 132364 KB Output is correct
5 Correct 0 ms 132364 KB Output is correct
6 Correct 0 ms 132364 KB Output is correct
7 Correct 0 ms 132364 KB Output is correct
8 Correct 0 ms 132364 KB Output is correct
9 Correct 0 ms 132364 KB Output is correct
10 Correct 0 ms 132364 KB Output is correct
11 Correct 0 ms 132364 KB Output is correct
12 Correct 0 ms 132364 KB Output is correct
13 Correct 0 ms 132364 KB Output is correct
14 Correct 0 ms 132364 KB Output is correct
15 Correct 0 ms 132364 KB Output is correct
16 Correct 0 ms 132364 KB Output is correct
17 Correct 0 ms 132364 KB Output is correct
18 Correct 0 ms 132364 KB Output is correct
19 Correct 0 ms 132364 KB Output is correct
20 Correct 0 ms 132364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 132364 KB Output is correct
2 Correct 0 ms 132364 KB Output is correct
3 Correct 0 ms 132364 KB Output is correct
4 Correct 0 ms 132364 KB Output is correct
5 Correct 0 ms 132364 KB Output is correct
6 Correct 0 ms 132364 KB Output is correct
7 Correct 0 ms 132364 KB Output is correct
8 Correct 0 ms 132364 KB Output is correct
9 Correct 0 ms 132364 KB Output is correct
10 Correct 0 ms 132364 KB Output is correct
11 Correct 0 ms 132364 KB Output is correct
12 Correct 0 ms 132364 KB Output is correct
13 Correct 0 ms 132364 KB Output is correct
14 Correct 0 ms 132364 KB Output is correct
15 Correct 0 ms 132364 KB Output is correct
16 Correct 0 ms 132364 KB Output is correct
17 Correct 0 ms 132364 KB Output is correct
18 Correct 0 ms 132364 KB Output is correct
19 Correct 0 ms 132364 KB Output is correct
20 Correct 0 ms 132364 KB Output is correct
21 Correct 46 ms 132364 KB Output is correct
22 Correct 73 ms 132364 KB Output is correct
23 Correct 23 ms 132364 KB Output is correct
24 Runtime error 243 ms 132364 KB Execution killed because of forbidden syscall writev (20)
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 132364 KB Output is correct
2 Correct 0 ms 132364 KB Output is correct
3 Correct 0 ms 132364 KB Output is correct
4 Correct 0 ms 132364 KB Output is correct
5 Correct 0 ms 132364 KB Output is correct
6 Correct 0 ms 132364 KB Output is correct
7 Correct 0 ms 132364 KB Output is correct
8 Correct 0 ms 132364 KB Output is correct
9 Correct 0 ms 132364 KB Output is correct
10 Correct 0 ms 132364 KB Output is correct
11 Correct 0 ms 132364 KB Output is correct
12 Correct 0 ms 132364 KB Output is correct
13 Correct 0 ms 132364 KB Output is correct
14 Correct 0 ms 132364 KB Output is correct
15 Correct 0 ms 132364 KB Output is correct
16 Correct 0 ms 132364 KB Output is correct
17 Correct 0 ms 132364 KB Output is correct
18 Correct 0 ms 132364 KB Output is correct
19 Correct 0 ms 132364 KB Output is correct
20 Correct 0 ms 132364 KB Output is correct
21 Correct 46 ms 132364 KB Output is correct
22 Correct 73 ms 132364 KB Output is correct
23 Correct 23 ms 132364 KB Output is correct
24 Runtime error 243 ms 132364 KB Execution killed because of forbidden syscall writev (20)
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 132364 KB Output is correct
2 Correct 0 ms 132364 KB Output is correct
3 Correct 0 ms 132364 KB Output is correct
4 Correct 0 ms 132364 KB Output is correct
5 Correct 0 ms 132364 KB Output is correct
6 Correct 0 ms 132364 KB Output is correct
7 Correct 0 ms 132364 KB Output is correct
8 Correct 0 ms 132364 KB Output is correct
9 Correct 0 ms 132364 KB Output is correct
10 Correct 0 ms 132364 KB Output is correct
11 Correct 0 ms 132364 KB Output is correct
12 Correct 0 ms 132364 KB Output is correct
13 Correct 0 ms 132364 KB Output is correct
14 Correct 0 ms 132364 KB Output is correct
15 Correct 0 ms 132364 KB Output is correct
16 Correct 0 ms 132364 KB Output is correct
17 Correct 0 ms 132364 KB Output is correct
18 Correct 0 ms 132364 KB Output is correct
19 Correct 0 ms 132364 KB Output is correct
20 Correct 0 ms 132364 KB Output is correct
21 Correct 46 ms 132364 KB Output is correct
22 Correct 73 ms 132364 KB Output is correct
23 Correct 23 ms 132364 KB Output is correct
24 Runtime error 243 ms 132364 KB Execution killed because of forbidden syscall writev (20)
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 132364 KB Output is correct
2 Correct 0 ms 132364 KB Output is correct
3 Correct 0 ms 132364 KB Output is correct
4 Correct 0 ms 132364 KB Output is correct
5 Correct 0 ms 132364 KB Output is correct
6 Correct 0 ms 132364 KB Output is correct
7 Correct 0 ms 132364 KB Output is correct
8 Correct 0 ms 132364 KB Output is correct
9 Correct 0 ms 132364 KB Output is correct
10 Correct 0 ms 132364 KB Output is correct
11 Correct 0 ms 132364 KB Output is correct
12 Correct 0 ms 132364 KB Output is correct
13 Correct 0 ms 132364 KB Output is correct
14 Correct 0 ms 132364 KB Output is correct
15 Correct 0 ms 132364 KB Output is correct
16 Correct 0 ms 132364 KB Output is correct
17 Correct 0 ms 132364 KB Output is correct
18 Correct 0 ms 132364 KB Output is correct
19 Correct 0 ms 132364 KB Output is correct
20 Correct 0 ms 132364 KB Output is correct
21 Correct 46 ms 132364 KB Output is correct
22 Correct 73 ms 132364 KB Output is correct
23 Correct 23 ms 132364 KB Output is correct
24 Runtime error 243 ms 132364 KB Execution killed because of forbidden syscall writev (20)
25 Halted 0 ms 0 KB -