답안 #858334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
858334 2023-10-08T06:51:48 Z nnhzzz Bootfall (IZhO17_bootfall) C++14
100 / 100
329 ms 3664 KB
// cre: Nguyen Ngoc Hung - Train VOI 2024 :>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <array>
#include <cassert>
#include <random>

using namespace std;

#define        __nnhzzz__  signed main()
#define          BIT(i,j)  ((i>>j)&1LL)
#define           MASK(i)  (1LL<<i)
#define            ALL(x)  (x).begin(),(x).end()
#define             SZ(x)  (int)(x).size()
#define                fi  first
#define                se  second
#define                ll  long long
#define                vi  vector<int>
#define               vvi  vector<vi>
#define               pii  pair<int,int>
#define              vpii  vector<pii>
#define REPDIS(i,be,en,j)  for(int i = (be); i<=(en); i+=j)
#define     REPD(i,be,en)  for(int i = (be); i>=(en); i--)
#define      REP(i,be,en)  for(int i = (be); i<=(en); i++)
//-------------------------------------------------------------//
const int oo = 1e9,LOG = 20,MAXN = 5e5+7,N = 250007;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }

/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Nguyen Ngoc Hung - nnhzzz
    Training for VOI24 gold medal
----------------------------------------------------------------
*/

void solve(){
    int s = 0,n; cin >> n;
    vi a(n+1);
    bitset<N> tmp; tmp[0] = 1;
    REP(i,1,n){
        cin >> a[i];
        s += a[i];
        tmp |= tmp<<a[i];
    }
    if(s%2==1 || tmp[s/2]==0){
        // cerr << 0;
        cout << 0; return ;
    }
    vi res;
    // REP(k,1,s){
    //     int ok = 1;
    //     REP(j,1,n){
    //         int t = s-a[j]+k;
    //         if(t%2==1){
    //             ok = 0; break;
    //         }
    //         bitset<N> dp(0); dp[0] = dp[k] = 1;
    //         REP(i,1,n){
    //             if(i==j) continue;
    //             dp |= dp<<a[i];
    //         }
    //         if(dp[t/2]==0){
    //             ok = 0; break;
    //         }
    //     }
    //     if(ok==1) res.push_back(k);
    // }
    vi dp(N+3,0),ok(N+3,1); dp[0] = 1;
    REP(i,1,n){
        REPD(j,s,a[i]){
            dp[j] += dp[j-a[i]];
        }
    }
    REP(ii,1,n){
        int x = a[ii];
        REP(i,x,s) dp[i] -= dp[i-x];
        REP(i,1,s){
            int t = s-x+i;
            if(t%2==1 || dp[t/2]==0){
                ok[i] = 0;
            }
        }
        REPD(i,s,x) dp[i] += dp[i-x];
    }
    REP(i,1,s){
        if(ok[i]==1){
            res.push_back(i);
        }
    }
    cout << SZ(res) << "\n";
    for(auto &i:res){
        cout << i << " ";
    }
}

__nnhzzz__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define name "test"
    if(fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    #define name1 "nnhzzz"
    if(fopen(name1".inp","r")){
        freopen(name1".inp","r",stdin);
        freopen(name1".out","w",stdout);
    }

    int test = 1;

    while(test--){
      solve();
    }
    cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:143:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  143 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:144:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  144 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:148:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  148 |         freopen(name1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:149:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |         freopen(name1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 4 ms 2396 KB Output is correct
26 Correct 4 ms 2396 KB Output is correct
27 Correct 5 ms 2552 KB Output is correct
28 Correct 4 ms 2516 KB Output is correct
29 Correct 4 ms 2396 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 4 ms 2396 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 4 ms 2392 KB Output is correct
34 Correct 4 ms 2396 KB Output is correct
35 Correct 5 ms 2396 KB Output is correct
36 Correct 3 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 4 ms 2396 KB Output is correct
26 Correct 4 ms 2396 KB Output is correct
27 Correct 5 ms 2552 KB Output is correct
28 Correct 4 ms 2516 KB Output is correct
29 Correct 4 ms 2396 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 4 ms 2396 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 4 ms 2392 KB Output is correct
34 Correct 4 ms 2396 KB Output is correct
35 Correct 5 ms 2396 KB Output is correct
36 Correct 3 ms 2396 KB Output is correct
37 Correct 12 ms 2652 KB Output is correct
38 Correct 13 ms 2648 KB Output is correct
39 Correct 46 ms 2648 KB Output is correct
40 Correct 25 ms 2508 KB Output is correct
41 Correct 52 ms 2392 KB Output is correct
42 Correct 22 ms 2516 KB Output is correct
43 Correct 37 ms 2760 KB Output is correct
44 Correct 38 ms 2640 KB Output is correct
45 Correct 39 ms 2644 KB Output is correct
46 Correct 26 ms 2488 KB Output is correct
47 Correct 28 ms 2652 KB Output is correct
48 Correct 42 ms 2764 KB Output is correct
49 Correct 42 ms 2504 KB Output is correct
50 Correct 24 ms 2652 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 52 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 4 ms 2396 KB Output is correct
26 Correct 4 ms 2396 KB Output is correct
27 Correct 5 ms 2552 KB Output is correct
28 Correct 4 ms 2516 KB Output is correct
29 Correct 4 ms 2396 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 4 ms 2396 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 4 ms 2392 KB Output is correct
34 Correct 4 ms 2396 KB Output is correct
35 Correct 5 ms 2396 KB Output is correct
36 Correct 3 ms 2396 KB Output is correct
37 Correct 12 ms 2652 KB Output is correct
38 Correct 13 ms 2648 KB Output is correct
39 Correct 46 ms 2648 KB Output is correct
40 Correct 25 ms 2508 KB Output is correct
41 Correct 52 ms 2392 KB Output is correct
42 Correct 22 ms 2516 KB Output is correct
43 Correct 37 ms 2760 KB Output is correct
44 Correct 38 ms 2640 KB Output is correct
45 Correct 39 ms 2644 KB Output is correct
46 Correct 26 ms 2488 KB Output is correct
47 Correct 28 ms 2652 KB Output is correct
48 Correct 42 ms 2764 KB Output is correct
49 Correct 42 ms 2504 KB Output is correct
50 Correct 24 ms 2652 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 52 ms 2764 KB Output is correct
53 Correct 40 ms 2764 KB Output is correct
54 Correct 52 ms 2644 KB Output is correct
55 Correct 102 ms 3024 KB Output is correct
56 Correct 46 ms 2896 KB Output is correct
57 Correct 114 ms 3128 KB Output is correct
58 Correct 57 ms 2752 KB Output is correct
59 Correct 70 ms 2896 KB Output is correct
60 Correct 2 ms 348 KB Output is correct
61 Correct 79 ms 2880 KB Output is correct
62 Correct 81 ms 2892 KB Output is correct
63 Correct 87 ms 3024 KB Output is correct
64 Correct 84 ms 2896 KB Output is correct
65 Correct 41 ms 2396 KB Output is correct
66 Correct 45 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2392 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 3 ms 2396 KB Output is correct
25 Correct 4 ms 2396 KB Output is correct
26 Correct 4 ms 2396 KB Output is correct
27 Correct 5 ms 2552 KB Output is correct
28 Correct 4 ms 2516 KB Output is correct
29 Correct 4 ms 2396 KB Output is correct
30 Correct 3 ms 2396 KB Output is correct
31 Correct 4 ms 2396 KB Output is correct
32 Correct 3 ms 2396 KB Output is correct
33 Correct 4 ms 2392 KB Output is correct
34 Correct 4 ms 2396 KB Output is correct
35 Correct 5 ms 2396 KB Output is correct
36 Correct 3 ms 2396 KB Output is correct
37 Correct 12 ms 2652 KB Output is correct
38 Correct 13 ms 2648 KB Output is correct
39 Correct 46 ms 2648 KB Output is correct
40 Correct 25 ms 2508 KB Output is correct
41 Correct 52 ms 2392 KB Output is correct
42 Correct 22 ms 2516 KB Output is correct
43 Correct 37 ms 2760 KB Output is correct
44 Correct 38 ms 2640 KB Output is correct
45 Correct 39 ms 2644 KB Output is correct
46 Correct 26 ms 2488 KB Output is correct
47 Correct 28 ms 2652 KB Output is correct
48 Correct 42 ms 2764 KB Output is correct
49 Correct 42 ms 2504 KB Output is correct
50 Correct 24 ms 2652 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 52 ms 2764 KB Output is correct
53 Correct 40 ms 2764 KB Output is correct
54 Correct 52 ms 2644 KB Output is correct
55 Correct 102 ms 3024 KB Output is correct
56 Correct 46 ms 2896 KB Output is correct
57 Correct 114 ms 3128 KB Output is correct
58 Correct 57 ms 2752 KB Output is correct
59 Correct 70 ms 2896 KB Output is correct
60 Correct 2 ms 348 KB Output is correct
61 Correct 79 ms 2880 KB Output is correct
62 Correct 81 ms 2892 KB Output is correct
63 Correct 87 ms 3024 KB Output is correct
64 Correct 84 ms 2896 KB Output is correct
65 Correct 41 ms 2396 KB Output is correct
66 Correct 45 ms 2512 KB Output is correct
67 Correct 84 ms 2880 KB Output is correct
68 Correct 3 ms 344 KB Output is correct
69 Correct 272 ms 3644 KB Output is correct
70 Correct 171 ms 3136 KB Output is correct
71 Correct 179 ms 3024 KB Output is correct
72 Correct 157 ms 2392 KB Output is correct
73 Correct 156 ms 2396 KB Output is correct
74 Correct 294 ms 3640 KB Output is correct
75 Correct 219 ms 3388 KB Output is correct
76 Correct 311 ms 3664 KB Output is correct
77 Correct 329 ms 3640 KB Output is correct