답안 #840344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
840344 2023-08-31T10:06:37 Z ASN49K Bootfall (IZhO17_bootfall) C++14
100 / 100
248 ms 2884 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <set>
#include <functional>
#include <bitset>
#include <map>
#include <unordered_map>
#include <queue>
#include <array>
#include <numeric>
#include <complex>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, vector<A>&a) { for(auto &c:a)os<<c<<' '; return os;}
template<typename A> istream& operator>>(istream  &os, vector<A>&a) { for(auto &c:a)os>>c; return os;}
template<typename A,size_t N> istream& operator>>(istream &os, array<A,N>&a) { for(auto &c:a)os>>c; return os;}
template<typename A,typename B> istream& operator>>(istream  &os, pair<A,B>&a) { os>>a.first>>a.second; return os;}
#define bug(a) cerr << "(" << #a << ": " << a << ")\n";
#define all(x) x.begin(),x.end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PQ priority_queue
using pii= pair<int,int>;
using VI= vector<int>;
using v64= vector<int64_t>;
using i64= int64_t;
using i16= int16_t;
using u64= uint64_t;
using u32= uint32_t;
using i32= int32_t;
using u16= uint16_t;
const i32 inf=1e9;
const i64 INF=1e18;
const int mod=1e9+7;
const int sigma=26;
string yn(bool x){if(x)return "YES";return "NO";}
typedef complex<double> point;
template<typename T>
void add(vector<T>&dp,const int& x)
{
    for(int i=int(dp.size())-1;i>=x;i--)
    {
        dp[i]+=dp[i-x];
    }
}
template<typename T>
void scot(vector<T>&dp,const int& x)
{
    for(int i=x;i<=int(dp.size())-1;i++)
    {
        dp[i]-=dp[i-x];
    }
}
const int N=500;
typedef bitset<N*N> bs;
//ifstream cin("bootfall.in");
//ofstream cout("bootfall.out");
void solve()
{
    int n;
    cin>>n;
    vector<int>a(n);
    cin>>a;
    int sum=accumulate(all(a),0);
    vector<u64>dp(sum+1,0);
    dp[0]=1;
    for(auto &c:a)
    {
        add(dp,c);
    }
    if(sum%2 || dp[sum/2]==0)
    {
        cout<<0;
        return;
    }
    bs sol;
    for(int i=0;i<=sum;i++)
    {
        sol[i].flip();
    }
    for(auto &c:a)
    {
        sum-=c;
        scot(dp,c);
        bs aux;
        for(int i=0;i<=sum/2;i++)
        {
            if(dp[i] > 0)
            {
                aux[sum-2*i].flip();
            }
        }
        sol&=aux;
        add(dp,c);
        sum+=c;
    }
    if(!sol.count())
    {
        cout<<0;
        return;
    }
    cout<<sol.count()<<'\n';
    for(int i=0;i<=sum;i++)
    {
        if(sol[i])
        {
            cout<<i<<' ';
        }
    }
}
main()
{
    i32 tt=1;
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
}

Compilation message

bootfall.cpp:116:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  116 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 3 ms 372 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 3 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 3 ms 372 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 3 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 9 ms 468 KB Output is correct
38 Correct 10 ms 552 KB Output is correct
39 Correct 28 ms 756 KB Output is correct
40 Correct 20 ms 644 KB Output is correct
41 Correct 37 ms 852 KB Output is correct
42 Correct 17 ms 624 KB Output is correct
43 Correct 30 ms 940 KB Output is correct
44 Correct 30 ms 948 KB Output is correct
45 Correct 35 ms 968 KB Output is correct
46 Correct 16 ms 628 KB Output is correct
47 Correct 19 ms 640 KB Output is correct
48 Correct 34 ms 852 KB Output is correct
49 Correct 37 ms 868 KB Output is correct
50 Correct 18 ms 648 KB Output is correct
51 Correct 5 ms 596 KB Output is correct
52 Correct 40 ms 1056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 3 ms 372 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 3 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 9 ms 468 KB Output is correct
38 Correct 10 ms 552 KB Output is correct
39 Correct 28 ms 756 KB Output is correct
40 Correct 20 ms 644 KB Output is correct
41 Correct 37 ms 852 KB Output is correct
42 Correct 17 ms 624 KB Output is correct
43 Correct 30 ms 940 KB Output is correct
44 Correct 30 ms 948 KB Output is correct
45 Correct 35 ms 968 KB Output is correct
46 Correct 16 ms 628 KB Output is correct
47 Correct 19 ms 640 KB Output is correct
48 Correct 34 ms 852 KB Output is correct
49 Correct 37 ms 868 KB Output is correct
50 Correct 18 ms 648 KB Output is correct
51 Correct 5 ms 596 KB Output is correct
52 Correct 40 ms 1056 KB Output is correct
53 Correct 30 ms 732 KB Output is correct
54 Correct 42 ms 952 KB Output is correct
55 Correct 83 ms 1504 KB Output is correct
56 Correct 37 ms 844 KB Output is correct
57 Correct 89 ms 1552 KB Output is correct
58 Correct 47 ms 980 KB Output is correct
59 Correct 66 ms 1104 KB Output is correct
60 Correct 11 ms 852 KB Output is correct
61 Correct 66 ms 1176 KB Output is correct
62 Correct 69 ms 1376 KB Output is correct
63 Correct 72 ms 1440 KB Output is correct
64 Correct 69 ms 1424 KB Output is correct
65 Correct 29 ms 724 KB Output is correct
66 Correct 32 ms 784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 376 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 3 ms 372 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 3 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 9 ms 468 KB Output is correct
38 Correct 10 ms 552 KB Output is correct
39 Correct 28 ms 756 KB Output is correct
40 Correct 20 ms 644 KB Output is correct
41 Correct 37 ms 852 KB Output is correct
42 Correct 17 ms 624 KB Output is correct
43 Correct 30 ms 940 KB Output is correct
44 Correct 30 ms 948 KB Output is correct
45 Correct 35 ms 968 KB Output is correct
46 Correct 16 ms 628 KB Output is correct
47 Correct 19 ms 640 KB Output is correct
48 Correct 34 ms 852 KB Output is correct
49 Correct 37 ms 868 KB Output is correct
50 Correct 18 ms 648 KB Output is correct
51 Correct 5 ms 596 KB Output is correct
52 Correct 40 ms 1056 KB Output is correct
53 Correct 30 ms 732 KB Output is correct
54 Correct 42 ms 952 KB Output is correct
55 Correct 83 ms 1504 KB Output is correct
56 Correct 37 ms 844 KB Output is correct
57 Correct 89 ms 1552 KB Output is correct
58 Correct 47 ms 980 KB Output is correct
59 Correct 66 ms 1104 KB Output is correct
60 Correct 11 ms 852 KB Output is correct
61 Correct 66 ms 1176 KB Output is correct
62 Correct 69 ms 1376 KB Output is correct
63 Correct 72 ms 1440 KB Output is correct
64 Correct 69 ms 1424 KB Output is correct
65 Correct 29 ms 724 KB Output is correct
66 Correct 32 ms 784 KB Output is correct
67 Correct 68 ms 1132 KB Output is correct
68 Correct 28 ms 1236 KB Output is correct
69 Correct 224 ms 2552 KB Output is correct
70 Correct 137 ms 1640 KB Output is correct
71 Correct 129 ms 1640 KB Output is correct
72 Correct 130 ms 1364 KB Output is correct
73 Correct 131 ms 1364 KB Output is correct
74 Correct 244 ms 2764 KB Output is correct
75 Correct 182 ms 2248 KB Output is correct
76 Correct 247 ms 2868 KB Output is correct
77 Correct 248 ms 2884 KB Output is correct