Submission #444341

# Submission time Handle Problem Language Result Execution time Memory
444341 2021-07-13T17:31:00 Z KiriLL1ca Bootfall (IZhO17_bootfall) C++14
13 / 100
39 ms 1388 KB
#include <bits/stdc++.h>

using namespace std;

/* 
written on phone :)))))
*/

const int N = 505;

int dp[N*N];
int ans[N*N];

void add (int x) {
    for (int i = N*N-1; i >= x; i--) {
        dp[i] += dp[i-x];
    }
}

void del (int x) {
    for (int i = x; i < N*N; i++) {
        dp[i] -= dp[i-x];
    }
}

int main ()
{
    dp[0] = 1;
    int n; cin >> n;
    vector <int> a (n);
    bitset <N*N> d; d[0]=1;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        d |= (d << a[i]);
        sum += a[i];
        add(a[i]);
    }
    if (sum & 1) {
        cout << 0; return 0;
    }
    if (!d[sum >> 1]) {
        cout << 0; return 0;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        del(a[i]); sum-=a[i];
        for (int j = sum&1; j <= N*N; j += 2) {
            int need = ((sum+j)>>1)-j;
            if (need >= 0 && dp[need] > 0) {
                ans[j]++;
            }
        }
        add(a[i]); sum+=a[i];
    }
    for (int i = 0; i < N*N;i++) {
        if (ans[i] == n) 
            cnt++;
    }
    cout << cnt << endl;
    for (int i = 0; i < N*N;i++) {
        if (ans[i] == n) 
            cout << i << " ";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1356 KB Output is correct
2 Correct 7 ms 1292 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 4 ms 1356 KB Output is correct
5 Correct 12 ms 1288 KB Output is correct
6 Correct 6 ms 1356 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
8 Correct 9 ms 1388 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1356 KB Output is correct
2 Correct 7 ms 1292 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 4 ms 1356 KB Output is correct
5 Correct 12 ms 1288 KB Output is correct
6 Correct 6 ms 1356 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
8 Correct 9 ms 1388 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
10 Correct 18 ms 1388 KB Output is correct
11 Correct 20 ms 1380 KB Output is correct
12 Correct 18 ms 1288 KB Output is correct
13 Correct 16 ms 1296 KB Output is correct
14 Correct 22 ms 1356 KB Output is correct
15 Correct 19 ms 1384 KB Output is correct
16 Correct 20 ms 1388 KB Output is correct
17 Correct 12 ms 1388 KB Output is correct
18 Correct 15 ms 1384 KB Output is correct
19 Correct 17 ms 1384 KB Output is correct
20 Correct 18 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1356 KB Output is correct
2 Correct 7 ms 1292 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 4 ms 1356 KB Output is correct
5 Correct 12 ms 1288 KB Output is correct
6 Correct 6 ms 1356 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
8 Correct 9 ms 1388 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
10 Correct 18 ms 1388 KB Output is correct
11 Correct 20 ms 1380 KB Output is correct
12 Correct 18 ms 1288 KB Output is correct
13 Correct 16 ms 1296 KB Output is correct
14 Correct 22 ms 1356 KB Output is correct
15 Correct 19 ms 1384 KB Output is correct
16 Correct 20 ms 1388 KB Output is correct
17 Correct 12 ms 1388 KB Output is correct
18 Correct 15 ms 1384 KB Output is correct
19 Correct 17 ms 1384 KB Output is correct
20 Correct 18 ms 1356 KB Output is correct
21 Incorrect 39 ms 1376 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1356 KB Output is correct
2 Correct 7 ms 1292 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 4 ms 1356 KB Output is correct
5 Correct 12 ms 1288 KB Output is correct
6 Correct 6 ms 1356 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
8 Correct 9 ms 1388 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
10 Correct 18 ms 1388 KB Output is correct
11 Correct 20 ms 1380 KB Output is correct
12 Correct 18 ms 1288 KB Output is correct
13 Correct 16 ms 1296 KB Output is correct
14 Correct 22 ms 1356 KB Output is correct
15 Correct 19 ms 1384 KB Output is correct
16 Correct 20 ms 1388 KB Output is correct
17 Correct 12 ms 1388 KB Output is correct
18 Correct 15 ms 1384 KB Output is correct
19 Correct 17 ms 1384 KB Output is correct
20 Correct 18 ms 1356 KB Output is correct
21 Incorrect 39 ms 1376 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1356 KB Output is correct
2 Correct 7 ms 1292 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 4 ms 1356 KB Output is correct
5 Correct 12 ms 1288 KB Output is correct
6 Correct 6 ms 1356 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
8 Correct 9 ms 1388 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
10 Correct 18 ms 1388 KB Output is correct
11 Correct 20 ms 1380 KB Output is correct
12 Correct 18 ms 1288 KB Output is correct
13 Correct 16 ms 1296 KB Output is correct
14 Correct 22 ms 1356 KB Output is correct
15 Correct 19 ms 1384 KB Output is correct
16 Correct 20 ms 1388 KB Output is correct
17 Correct 12 ms 1388 KB Output is correct
18 Correct 15 ms 1384 KB Output is correct
19 Correct 17 ms 1384 KB Output is correct
20 Correct 18 ms 1356 KB Output is correct
21 Incorrect 39 ms 1376 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1356 KB Output is correct
2 Correct 7 ms 1292 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 4 ms 1356 KB Output is correct
5 Correct 12 ms 1288 KB Output is correct
6 Correct 6 ms 1356 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
8 Correct 9 ms 1388 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
10 Correct 18 ms 1388 KB Output is correct
11 Correct 20 ms 1380 KB Output is correct
12 Correct 18 ms 1288 KB Output is correct
13 Correct 16 ms 1296 KB Output is correct
14 Correct 22 ms 1356 KB Output is correct
15 Correct 19 ms 1384 KB Output is correct
16 Correct 20 ms 1388 KB Output is correct
17 Correct 12 ms 1388 KB Output is correct
18 Correct 15 ms 1384 KB Output is correct
19 Correct 17 ms 1384 KB Output is correct
20 Correct 18 ms 1356 KB Output is correct
21 Incorrect 39 ms 1376 KB Output isn't correct
22 Halted 0 ms 0 KB -