답안 #173622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173622 2020-01-04T17:39:26 Z aleks5d Bootfall (IZhO17_bootfall) C++17
65 / 100
1000 ms 6912 KB
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;

namespace HASH {
const ll mod197 = 1e9 + 7;
const ll mod199 = 1e9 + 9;
const ll modfft = 998244353;
ll MOD = mod197;
void Hplus(ll& h, ll b, ll mod = MOD) {
    h += b;
    if (h > mod)
        h -= mod;
}

void Hminus(ll& h, ll b, ll mod = MOD) {
    h -= b;
    if (h < 0)
        h += mod;
}

void Hmuliply(ll& h, ll b, ll mod = MOD) {
    h *= b;
    h %= mod;
}

ll Hdivider(ll x, ll mod = MOD) {
    if (x < 0)
        x += mod;
    ll ans = 1;
    ll n = mod - 2;
    while (n) {
        if (n & 1)
            Hmuliply(ans, x);
        n >>= 1;
        Hmuliply(x, x);
    }
    return ans;
}
}

namespace someUsefull {
template<typename T1, typename T2>
inline void checkMin(T1& a, T2 b) {
    if (a > b)
        a = b;
}

template<typename T1, typename T2>
inline void checkMax(T1& a, T2 b) {
    if (a < b)
        a = b;
}
}

//name spaces
using namespace std;
using namespace HASH;
using namespace someUsefull;
//end of name spaces

//defines
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()

#define NO cout << "NO" << '\n';
#define YES cout << "YES" << '\n';
//end of defines

//debug defines
#ifdef HOME
    #define debug(x) cout << #x << " " << x << endl;
    #define debug_p(x) cout << #x << " " << x.ff << " " << x.ss << endl;
    #define debug_v(x) {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
    #define debug_vp(x) {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.ff << " " << ioi.ss << ']'; cout << endl;}
    #define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}
    int jjj;
    #define wait() cin >> jjj;
    #define PO cout << "POMELO" << endl;
    #define OL cout << "OLIVA" << endl;
    #define gen_clock(x) ll x = clock(); cout << "Clock " << #x << " created" << endl;
    #define check_clock(x) cout << "Time spent in " << #x << ": " << clock() - x << endl; x = clock();
    #define reset_clock(x) x = clock();
    #define say(x) cout << x << endl;
#else
    #define debug(x) 0;
    #define debug_p(x) 0;
    #define debug_v(x) 0;
    #define debug_vp(x) 0;
    #define debug_v_v(x) 0;
    #define wait() 0;
    #define PO 0;
    #define OL 0;
    #define gen_clock(x) 0;
    #define check_clock(x) 0;
    #define reset_clock(x) 0;
    #define say(x) 0;
#endif // HOME
//end of debug defines

void solve() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i)
        cin >> arr[i];
    vector<ll> dp(3e5);
    vector<int> canbe(3e5, 0);
    vector<ll> dp2(3e5);
    dp[0] = 1;
    dp2[0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = dp.size() - 1; j >= arr[i]; --j) {
            Hplus(dp[j], dp[j - arr[i]]);
            Hplus(dp2[j], dp2[j - arr[i]], modfft);
        }
    }
    int ma = 0;
    for (int j = dp.size() - 1; j > 0; --j)
    if (dp[j] || dp2[j]) {
        ma = j;
        break;
    }
    if (ma & 1) {
        cout << 0;
        return;
    }
    if (dp[ma >> 1] == 0 && dp2[ma >> 1] == 0) {
        cout << 0;
        return;
    }
    for (int i = 0; i < n; ++i) {
        if (i != -1) {
            for (int j = arr[i]; j < dp.size(); ++j) {
                Hminus(dp[j], dp[j - arr[i]]);
                Hminus(dp2[j], dp2[j - arr[i]], modfft);
            }
        }
        int ma = 0;
        for (int i = dp.size() - 1; i > 0; --i) {
            if (dp[i] || dp2[i]) {
                ma = i;
                break;
            }
        }
        debug(i);
        //vector<int> opa(dp.begin(), dp.begin() + ma + 1);
        //debug_v(opa);
        debug(ma);
        for (int i = 0; i * 2 <= ma; ++i) {
            if (dp[i] || dp2[i]) {
                debug(i);
                debug(ma - i - i);
                ++canbe[ma - i - i];
            }
        }
        if (i != -1) {
            for (int j = dp.size() - 1; j >= arr[i]; --j) {
                Hplus(dp[j], dp[j - arr[i]]);
                Hplus(dp2[j], dp2[j - arr[i]], modfft);
            }
        }
    }
    vector<int> ans;
    for (int i = 0; i < dp.size(); ++i) {
        if (canbe[i] == n) {
            ans.push_back(i);
        }
    }
    cout << ans.size() << '\n';
    for (int i : ans)
        cout << i << " ";

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    t = 1;
  // cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
        cout << '\n';
    }
    return 0;

}

/*
5
3 2
3 -2
-2 -2
-2 2
0 0
*/

Compilation message

bootfall.cpp: In function 'void solve()':
bootfall.cpp:140:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = arr[i]; j < dp.size(); ++j) {
                                  ~~^~~~~~~~~~~
bootfall.cpp:92:23: warning: statement has no effect [-Wunused-value]
     #define debug(x) 0;
                       ^
bootfall.cpp:152:9: note: in expansion of macro 'debug'
         debug(i);
         ^~~~~
bootfall.cpp:92:23: warning: statement has no effect [-Wunused-value]
     #define debug(x) 0;
                       ^
bootfall.cpp:155:9: note: in expansion of macro 'debug'
         debug(ma);
         ^~~~~
bootfall.cpp:92:23: warning: statement has no effect [-Wunused-value]
     #define debug(x) 0;
                       ^
bootfall.cpp:158:17: note: in expansion of macro 'debug'
                 debug(i);
                 ^~~~~
bootfall.cpp:92:23: warning: statement has no effect [-Wunused-value]
     #define debug(x) 0;
                       ^
bootfall.cpp:159:17: note: in expansion of macro 'debug'
                 debug(ma - i - i);
                 ^~~~~
bootfall.cpp:171:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < dp.size(); ++i) {
                     ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6264 KB Output is correct
2 Correct 23 ms 6136 KB Output is correct
3 Correct 9 ms 6140 KB Output is correct
4 Correct 18 ms 6140 KB Output is correct
5 Correct 37 ms 6264 KB Output is correct
6 Correct 27 ms 6264 KB Output is correct
7 Correct 23 ms 6264 KB Output is correct
8 Correct 37 ms 6264 KB Output is correct
9 Correct 32 ms 6264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6264 KB Output is correct
2 Correct 23 ms 6136 KB Output is correct
3 Correct 9 ms 6140 KB Output is correct
4 Correct 18 ms 6140 KB Output is correct
5 Correct 37 ms 6264 KB Output is correct
6 Correct 27 ms 6264 KB Output is correct
7 Correct 23 ms 6264 KB Output is correct
8 Correct 37 ms 6264 KB Output is correct
9 Correct 32 ms 6264 KB Output is correct
10 Correct 80 ms 6136 KB Output is correct
11 Correct 82 ms 6256 KB Output is correct
12 Correct 81 ms 6136 KB Output is correct
13 Correct 72 ms 6256 KB Output is correct
14 Correct 77 ms 6140 KB Output is correct
15 Correct 78 ms 6264 KB Output is correct
16 Correct 84 ms 6256 KB Output is correct
17 Correct 52 ms 6136 KB Output is correct
18 Correct 67 ms 6264 KB Output is correct
19 Correct 72 ms 6136 KB Output is correct
20 Correct 82 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6264 KB Output is correct
2 Correct 23 ms 6136 KB Output is correct
3 Correct 9 ms 6140 KB Output is correct
4 Correct 18 ms 6140 KB Output is correct
5 Correct 37 ms 6264 KB Output is correct
6 Correct 27 ms 6264 KB Output is correct
7 Correct 23 ms 6264 KB Output is correct
8 Correct 37 ms 6264 KB Output is correct
9 Correct 32 ms 6264 KB Output is correct
10 Correct 80 ms 6136 KB Output is correct
11 Correct 82 ms 6256 KB Output is correct
12 Correct 81 ms 6136 KB Output is correct
13 Correct 72 ms 6256 KB Output is correct
14 Correct 77 ms 6140 KB Output is correct
15 Correct 78 ms 6264 KB Output is correct
16 Correct 84 ms 6256 KB Output is correct
17 Correct 52 ms 6136 KB Output is correct
18 Correct 67 ms 6264 KB Output is correct
19 Correct 72 ms 6136 KB Output is correct
20 Correct 82 ms 6136 KB Output is correct
21 Correct 163 ms 6260 KB Output is correct
22 Correct 191 ms 6260 KB Output is correct
23 Correct 130 ms 6264 KB Output is correct
24 Correct 243 ms 6256 KB Output is correct
25 Correct 237 ms 6264 KB Output is correct
26 Correct 250 ms 6264 KB Output is correct
27 Correct 253 ms 6264 KB Output is correct
28 Correct 249 ms 6260 KB Output is correct
29 Correct 252 ms 6392 KB Output is correct
30 Correct 252 ms 6392 KB Output is correct
31 Correct 253 ms 6264 KB Output is correct
32 Correct 252 ms 6392 KB Output is correct
33 Correct 248 ms 6392 KB Output is correct
34 Correct 253 ms 6236 KB Output is correct
35 Correct 251 ms 6392 KB Output is correct
36 Correct 253 ms 6264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6264 KB Output is correct
2 Correct 23 ms 6136 KB Output is correct
3 Correct 9 ms 6140 KB Output is correct
4 Correct 18 ms 6140 KB Output is correct
5 Correct 37 ms 6264 KB Output is correct
6 Correct 27 ms 6264 KB Output is correct
7 Correct 23 ms 6264 KB Output is correct
8 Correct 37 ms 6264 KB Output is correct
9 Correct 32 ms 6264 KB Output is correct
10 Correct 80 ms 6136 KB Output is correct
11 Correct 82 ms 6256 KB Output is correct
12 Correct 81 ms 6136 KB Output is correct
13 Correct 72 ms 6256 KB Output is correct
14 Correct 77 ms 6140 KB Output is correct
15 Correct 78 ms 6264 KB Output is correct
16 Correct 84 ms 6256 KB Output is correct
17 Correct 52 ms 6136 KB Output is correct
18 Correct 67 ms 6264 KB Output is correct
19 Correct 72 ms 6136 KB Output is correct
20 Correct 82 ms 6136 KB Output is correct
21 Correct 163 ms 6260 KB Output is correct
22 Correct 191 ms 6260 KB Output is correct
23 Correct 130 ms 6264 KB Output is correct
24 Correct 243 ms 6256 KB Output is correct
25 Correct 237 ms 6264 KB Output is correct
26 Correct 250 ms 6264 KB Output is correct
27 Correct 253 ms 6264 KB Output is correct
28 Correct 249 ms 6260 KB Output is correct
29 Correct 252 ms 6392 KB Output is correct
30 Correct 252 ms 6392 KB Output is correct
31 Correct 253 ms 6264 KB Output is correct
32 Correct 252 ms 6392 KB Output is correct
33 Correct 248 ms 6392 KB Output is correct
34 Correct 253 ms 6236 KB Output is correct
35 Correct 251 ms 6392 KB Output is correct
36 Correct 253 ms 6264 KB Output is correct
37 Correct 488 ms 6520 KB Output is correct
38 Correct 499 ms 6392 KB Output is correct
39 Correct 607 ms 6264 KB Output is correct
40 Correct 664 ms 6520 KB Output is correct
41 Correct 653 ms 6264 KB Output is correct
42 Correct 615 ms 6520 KB Output is correct
43 Correct 608 ms 6776 KB Output is correct
44 Correct 609 ms 6652 KB Output is correct
45 Correct 614 ms 6648 KB Output is correct
46 Correct 659 ms 6268 KB Output is correct
47 Correct 613 ms 6392 KB Output is correct
48 Correct 616 ms 6520 KB Output is correct
49 Correct 610 ms 6264 KB Output is correct
50 Correct 619 ms 6392 KB Output is correct
51 Correct 183 ms 6392 KB Output is correct
52 Correct 659 ms 6636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6264 KB Output is correct
2 Correct 23 ms 6136 KB Output is correct
3 Correct 9 ms 6140 KB Output is correct
4 Correct 18 ms 6140 KB Output is correct
5 Correct 37 ms 6264 KB Output is correct
6 Correct 27 ms 6264 KB Output is correct
7 Correct 23 ms 6264 KB Output is correct
8 Correct 37 ms 6264 KB Output is correct
9 Correct 32 ms 6264 KB Output is correct
10 Correct 80 ms 6136 KB Output is correct
11 Correct 82 ms 6256 KB Output is correct
12 Correct 81 ms 6136 KB Output is correct
13 Correct 72 ms 6256 KB Output is correct
14 Correct 77 ms 6140 KB Output is correct
15 Correct 78 ms 6264 KB Output is correct
16 Correct 84 ms 6256 KB Output is correct
17 Correct 52 ms 6136 KB Output is correct
18 Correct 67 ms 6264 KB Output is correct
19 Correct 72 ms 6136 KB Output is correct
20 Correct 82 ms 6136 KB Output is correct
21 Correct 163 ms 6260 KB Output is correct
22 Correct 191 ms 6260 KB Output is correct
23 Correct 130 ms 6264 KB Output is correct
24 Correct 243 ms 6256 KB Output is correct
25 Correct 237 ms 6264 KB Output is correct
26 Correct 250 ms 6264 KB Output is correct
27 Correct 253 ms 6264 KB Output is correct
28 Correct 249 ms 6260 KB Output is correct
29 Correct 252 ms 6392 KB Output is correct
30 Correct 252 ms 6392 KB Output is correct
31 Correct 253 ms 6264 KB Output is correct
32 Correct 252 ms 6392 KB Output is correct
33 Correct 248 ms 6392 KB Output is correct
34 Correct 253 ms 6236 KB Output is correct
35 Correct 251 ms 6392 KB Output is correct
36 Correct 253 ms 6264 KB Output is correct
37 Correct 488 ms 6520 KB Output is correct
38 Correct 499 ms 6392 KB Output is correct
39 Correct 607 ms 6264 KB Output is correct
40 Correct 664 ms 6520 KB Output is correct
41 Correct 653 ms 6264 KB Output is correct
42 Correct 615 ms 6520 KB Output is correct
43 Correct 608 ms 6776 KB Output is correct
44 Correct 609 ms 6652 KB Output is correct
45 Correct 614 ms 6648 KB Output is correct
46 Correct 659 ms 6268 KB Output is correct
47 Correct 613 ms 6392 KB Output is correct
48 Correct 616 ms 6520 KB Output is correct
49 Correct 610 ms 6264 KB Output is correct
50 Correct 619 ms 6392 KB Output is correct
51 Correct 183 ms 6392 KB Output is correct
52 Correct 659 ms 6636 KB Output is correct
53 Correct 730 ms 6516 KB Output is correct
54 Correct 857 ms 6552 KB Output is correct
55 Correct 849 ms 6768 KB Output is correct
56 Correct 767 ms 6648 KB Output is correct
57 Correct 877 ms 6912 KB Output is correct
58 Correct 853 ms 6656 KB Output is correct
59 Correct 854 ms 6648 KB Output is correct
60 Correct 255 ms 6264 KB Output is correct
61 Correct 854 ms 6876 KB Output is correct
62 Correct 781 ms 6876 KB Output is correct
63 Correct 778 ms 6876 KB Output is correct
64 Correct 761 ms 6808 KB Output is correct
65 Correct 772 ms 6264 KB Output is correct
66 Correct 760 ms 6300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6264 KB Output is correct
2 Correct 23 ms 6136 KB Output is correct
3 Correct 9 ms 6140 KB Output is correct
4 Correct 18 ms 6140 KB Output is correct
5 Correct 37 ms 6264 KB Output is correct
6 Correct 27 ms 6264 KB Output is correct
7 Correct 23 ms 6264 KB Output is correct
8 Correct 37 ms 6264 KB Output is correct
9 Correct 32 ms 6264 KB Output is correct
10 Correct 80 ms 6136 KB Output is correct
11 Correct 82 ms 6256 KB Output is correct
12 Correct 81 ms 6136 KB Output is correct
13 Correct 72 ms 6256 KB Output is correct
14 Correct 77 ms 6140 KB Output is correct
15 Correct 78 ms 6264 KB Output is correct
16 Correct 84 ms 6256 KB Output is correct
17 Correct 52 ms 6136 KB Output is correct
18 Correct 67 ms 6264 KB Output is correct
19 Correct 72 ms 6136 KB Output is correct
20 Correct 82 ms 6136 KB Output is correct
21 Correct 163 ms 6260 KB Output is correct
22 Correct 191 ms 6260 KB Output is correct
23 Correct 130 ms 6264 KB Output is correct
24 Correct 243 ms 6256 KB Output is correct
25 Correct 237 ms 6264 KB Output is correct
26 Correct 250 ms 6264 KB Output is correct
27 Correct 253 ms 6264 KB Output is correct
28 Correct 249 ms 6260 KB Output is correct
29 Correct 252 ms 6392 KB Output is correct
30 Correct 252 ms 6392 KB Output is correct
31 Correct 253 ms 6264 KB Output is correct
32 Correct 252 ms 6392 KB Output is correct
33 Correct 248 ms 6392 KB Output is correct
34 Correct 253 ms 6236 KB Output is correct
35 Correct 251 ms 6392 KB Output is correct
36 Correct 253 ms 6264 KB Output is correct
37 Correct 488 ms 6520 KB Output is correct
38 Correct 499 ms 6392 KB Output is correct
39 Correct 607 ms 6264 KB Output is correct
40 Correct 664 ms 6520 KB Output is correct
41 Correct 653 ms 6264 KB Output is correct
42 Correct 615 ms 6520 KB Output is correct
43 Correct 608 ms 6776 KB Output is correct
44 Correct 609 ms 6652 KB Output is correct
45 Correct 614 ms 6648 KB Output is correct
46 Correct 659 ms 6268 KB Output is correct
47 Correct 613 ms 6392 KB Output is correct
48 Correct 616 ms 6520 KB Output is correct
49 Correct 610 ms 6264 KB Output is correct
50 Correct 619 ms 6392 KB Output is correct
51 Correct 183 ms 6392 KB Output is correct
52 Correct 659 ms 6636 KB Output is correct
53 Correct 730 ms 6516 KB Output is correct
54 Correct 857 ms 6552 KB Output is correct
55 Correct 849 ms 6768 KB Output is correct
56 Correct 767 ms 6648 KB Output is correct
57 Correct 877 ms 6912 KB Output is correct
58 Correct 853 ms 6656 KB Output is correct
59 Correct 854 ms 6648 KB Output is correct
60 Correct 255 ms 6264 KB Output is correct
61 Correct 854 ms 6876 KB Output is correct
62 Correct 781 ms 6876 KB Output is correct
63 Correct 778 ms 6876 KB Output is correct
64 Correct 761 ms 6808 KB Output is correct
65 Correct 772 ms 6264 KB Output is correct
66 Correct 760 ms 6300 KB Output is correct
67 Correct 973 ms 6684 KB Output is correct
68 Correct 363 ms 6364 KB Output is correct
69 Execution timed out 1071 ms 6264 KB Time limit exceeded
70 Halted 0 ms 0 KB -