Submission #1088838

# Submission time Handle Problem Language Result Execution time Memory
1088838 2024-09-15T09:41:25 Z vjudge1 Bootfall (IZhO17_bootfall) C++
100 / 100
784 ms 4376 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
    double cur = rngesus(0, MASK(60) - 1);
    cur /= MASK(60) - 1;
    return l + cur * (r - l);
}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const ll MOD = 1000000007LL * 1000000009;

int main(void){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    clock_t start = clock();

    int n; cin >> n;
    vector<int> a(n);
    for(int i= 0; i<n; ++i) cin >> a[i];

    int s = 0;
    for(int i: a) s += i;

    vector<ll> dp(s + 1);
    dp[0] = 1;
    for(int i: a){
        for(int j = s; j >= i; --j){
            dp[j] += dp[j - i];
            if (dp[j] >= MOD) dp[j] -= MOD;
        }
    }

    if (s % 2 || dp[s / 2] == 0){
        cout << 0 << "\n";
        return 0;
    }

    vector<int> valid;
    for(int i = 1; i<=s; ++i) valid.push_back(i);

    for(int i: a){
        for(int j = i; j <= s; ++j){
            dp[j] -= dp[j - i];
            if (dp[j] < 0) dp[j] += MOD;
        }
        int _s = s - i;
        vector<int> tmp; tmp.reserve(valid.size());
        for(int j: valid){
            int l = (_s - j), r = (_s + j);
            if (r <= s * 2 && r % 2 == 0 && dp[r / 2]){
                tmp.push_back(j);
            }
        }
        valid = tmp;

        for(int j = s; j >= i; --j){
            dp[j] += dp[j - i];
            if (dp[j] >= MOD) dp[j] -= MOD;
        }
    }

    cout << valid.size() << "\n";
    printArr(valid);

    cerr << "Time elapsed: " << clock() - start << " ms\n";
    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:93:17: warning: unused variable 'l' [-Wunused-variable]
   93 |             int l = (_s - j), r = (_s + j);
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 604 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 604 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 604 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 604 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 25 ms 1112 KB Output is correct
38 Correct 26 ms 856 KB Output is correct
39 Correct 36 ms 1248 KB Output is correct
40 Correct 58 ms 1048 KB Output is correct
41 Correct 47 ms 1504 KB Output is correct
42 Correct 49 ms 856 KB Output is correct
43 Correct 89 ms 1248 KB Output is correct
44 Correct 87 ms 1388 KB Output is correct
45 Correct 116 ms 1384 KB Output is correct
46 Correct 34 ms 860 KB Output is correct
47 Correct 56 ms 1108 KB Output is correct
48 Correct 81 ms 1404 KB Output is correct
49 Correct 64 ms 1244 KB Output is correct
50 Correct 53 ms 1104 KB Output is correct
51 Correct 6 ms 600 KB Output is correct
52 Correct 113 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 604 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 604 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 25 ms 1112 KB Output is correct
38 Correct 26 ms 856 KB Output is correct
39 Correct 36 ms 1248 KB Output is correct
40 Correct 58 ms 1048 KB Output is correct
41 Correct 47 ms 1504 KB Output is correct
42 Correct 49 ms 856 KB Output is correct
43 Correct 89 ms 1248 KB Output is correct
44 Correct 87 ms 1388 KB Output is correct
45 Correct 116 ms 1384 KB Output is correct
46 Correct 34 ms 860 KB Output is correct
47 Correct 56 ms 1108 KB Output is correct
48 Correct 81 ms 1404 KB Output is correct
49 Correct 64 ms 1244 KB Output is correct
50 Correct 53 ms 1104 KB Output is correct
51 Correct 6 ms 600 KB Output is correct
52 Correct 113 ms 1664 KB Output is correct
53 Correct 88 ms 1148 KB Output is correct
54 Correct 130 ms 1244 KB Output is correct
55 Correct 273 ms 2216 KB Output is correct
56 Correct 110 ms 1380 KB Output is correct
57 Correct 260 ms 2312 KB Output is correct
58 Correct 140 ms 1368 KB Output is correct
59 Correct 172 ms 1500 KB Output is correct
60 Correct 15 ms 860 KB Output is correct
61 Correct 193 ms 1888 KB Output is correct
62 Correct 196 ms 1816 KB Output is correct
63 Correct 208 ms 2060 KB Output is correct
64 Correct 204 ms 2104 KB Output is correct
65 Correct 39 ms 1112 KB Output is correct
66 Correct 52 ms 1220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 604 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 4 ms 604 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 604 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 25 ms 1112 KB Output is correct
38 Correct 26 ms 856 KB Output is correct
39 Correct 36 ms 1248 KB Output is correct
40 Correct 58 ms 1048 KB Output is correct
41 Correct 47 ms 1504 KB Output is correct
42 Correct 49 ms 856 KB Output is correct
43 Correct 89 ms 1248 KB Output is correct
44 Correct 87 ms 1388 KB Output is correct
45 Correct 116 ms 1384 KB Output is correct
46 Correct 34 ms 860 KB Output is correct
47 Correct 56 ms 1108 KB Output is correct
48 Correct 81 ms 1404 KB Output is correct
49 Correct 64 ms 1244 KB Output is correct
50 Correct 53 ms 1104 KB Output is correct
51 Correct 6 ms 600 KB Output is correct
52 Correct 113 ms 1664 KB Output is correct
53 Correct 88 ms 1148 KB Output is correct
54 Correct 130 ms 1244 KB Output is correct
55 Correct 273 ms 2216 KB Output is correct
56 Correct 110 ms 1380 KB Output is correct
57 Correct 260 ms 2312 KB Output is correct
58 Correct 140 ms 1368 KB Output is correct
59 Correct 172 ms 1500 KB Output is correct
60 Correct 15 ms 860 KB Output is correct
61 Correct 193 ms 1888 KB Output is correct
62 Correct 196 ms 1816 KB Output is correct
63 Correct 208 ms 2060 KB Output is correct
64 Correct 204 ms 2104 KB Output is correct
65 Correct 39 ms 1112 KB Output is correct
66 Correct 52 ms 1220 KB Output is correct
67 Correct 210 ms 1588 KB Output is correct
68 Correct 44 ms 1368 KB Output is correct
69 Correct 691 ms 3896 KB Output is correct
70 Correct 421 ms 2516 KB Output is correct
71 Correct 414 ms 2520 KB Output is correct
72 Correct 353 ms 2252 KB Output is correct
73 Correct 358 ms 2256 KB Output is correct
74 Correct 727 ms 4036 KB Output is correct
75 Correct 562 ms 3388 KB Output is correct
76 Correct 752 ms 4376 KB Output is correct
77 Correct 784 ms 4356 KB Output is correct