Submission #144036

# Submission time Handle Problem Language Result Execution time Memory
144036 2019-08-15T18:19:36 Z The_Wolfpack Bootfall (IZhO17_bootfall) C++14
100 / 100
651 ms 4596 KB
#include <bits/stdc++.h>
using namespace std;
const int NMAX=502;
const int KMAX=502*502;

int n,a[NMAX],dp[KMAX],moze[KMAX],vis[KMAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int sum=0;
    for(int i=1;i<=n;i++) sum+=a[i];
    dp[0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=KMAX-1;j>=0;j--)
        {
            if(j-a[i]>=0) dp[j]+=dp[j-a[i]];
        }
    }
    //for(int i=0;i<20;i++) cout<<dp[i]<<endl;
    if(sum&1 || !dp[sum/2])
    {
        cout<<"0"<<endl;
        return 0;
    }
    vector<int> ans;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=KMAX-1;j++)
        {
            if(j-a[i]>=0) dp[j]-=dp[j-a[i]];
        }
        /*for(int i=0;i<12;i++) cout<<dp[i]<< " ";
        cout<<endl;*/
        memset(vis,0,sizeof(vis));
        for(int j=1;j<=sum-a[i];j++)
        {
            if(!dp[j]) continue;
            //if(i==4) cout<<j<<"A"<<endl;
            if(!vis[abs(sum-2*j-a[i])]) moze[abs(sum-2*j-a[i])]++;
            vis[abs(sum-2*j-a[i])]=1;
            /*if(sum-j-a[i] > j)
            {
                if(!vis[sum-2*j-a[i]]) moze[sum-2*j-a[i]]++;
                vis[sum-2*j-a[i]]=1;
                //if(i==4) cout<<sum-2*j-a[i]<<"A"<<endl;
                //ans.push_back(sum-2*j-a[i]);
            }
            else
            {
                if(!vis[2*j+a[i]-sum]) moze[2*j+a[i]-sum]++;
                vis[2*j+a[i]-sum]=1;
                //if(i==4) cout<<2*j+a[i]-sum<<"A"<<endl;
            }*/
        }
        for(int j=KMAX-1;j>=0;j--)
        {
            if(j-a[i]>=0) dp[j]+=dp[j-a[i]];
        }
        /*for(int i=0;i<10;i++) cout<<moze[i]<<" ";
        cout<<endl;*/
    }
    /*sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());*/
    for(int i=1;i<=KMAX-1;i++) if(moze[i]==n) ans.push_back(i);
    cout<<ans.size()<<endl;
    for(int i:ans) cout<<i<<" ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 10 ms 2296 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 15 ms 2296 KB Output is correct
6 Correct 12 ms 2296 KB Output is correct
7 Correct 10 ms 2296 KB Output is correct
8 Correct 15 ms 2296 KB Output is correct
9 Correct 13 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 10 ms 2296 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 15 ms 2296 KB Output is correct
6 Correct 12 ms 2296 KB Output is correct
7 Correct 10 ms 2296 KB Output is correct
8 Correct 15 ms 2296 KB Output is correct
9 Correct 13 ms 2296 KB Output is correct
10 Correct 31 ms 2296 KB Output is correct
11 Correct 32 ms 2296 KB Output is correct
12 Correct 30 ms 2296 KB Output is correct
13 Correct 27 ms 2296 KB Output is correct
14 Correct 29 ms 2296 KB Output is correct
15 Correct 30 ms 2296 KB Output is correct
16 Correct 32 ms 2296 KB Output is correct
17 Correct 21 ms 2296 KB Output is correct
18 Correct 26 ms 2428 KB Output is correct
19 Correct 28 ms 2424 KB Output is correct
20 Correct 32 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 10 ms 2296 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 15 ms 2296 KB Output is correct
6 Correct 12 ms 2296 KB Output is correct
7 Correct 10 ms 2296 KB Output is correct
8 Correct 15 ms 2296 KB Output is correct
9 Correct 13 ms 2296 KB Output is correct
10 Correct 31 ms 2296 KB Output is correct
11 Correct 32 ms 2296 KB Output is correct
12 Correct 30 ms 2296 KB Output is correct
13 Correct 27 ms 2296 KB Output is correct
14 Correct 29 ms 2296 KB Output is correct
15 Correct 30 ms 2296 KB Output is correct
16 Correct 32 ms 2296 KB Output is correct
17 Correct 21 ms 2296 KB Output is correct
18 Correct 26 ms 2428 KB Output is correct
19 Correct 28 ms 2424 KB Output is correct
20 Correct 32 ms 2296 KB Output is correct
21 Correct 60 ms 2368 KB Output is correct
22 Correct 68 ms 2300 KB Output is correct
23 Correct 48 ms 2372 KB Output is correct
24 Correct 86 ms 2296 KB Output is correct
25 Correct 86 ms 2392 KB Output is correct
26 Correct 92 ms 2400 KB Output is correct
27 Correct 90 ms 2424 KB Output is correct
28 Correct 90 ms 2424 KB Output is correct
29 Correct 91 ms 2468 KB Output is correct
30 Correct 89 ms 2296 KB Output is correct
31 Correct 91 ms 2428 KB Output is correct
32 Correct 90 ms 2296 KB Output is correct
33 Correct 90 ms 2424 KB Output is correct
34 Correct 90 ms 2424 KB Output is correct
35 Correct 90 ms 2296 KB Output is correct
36 Correct 92 ms 2532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 10 ms 2296 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 15 ms 2296 KB Output is correct
6 Correct 12 ms 2296 KB Output is correct
7 Correct 10 ms 2296 KB Output is correct
8 Correct 15 ms 2296 KB Output is correct
9 Correct 13 ms 2296 KB Output is correct
10 Correct 31 ms 2296 KB Output is correct
11 Correct 32 ms 2296 KB Output is correct
12 Correct 30 ms 2296 KB Output is correct
13 Correct 27 ms 2296 KB Output is correct
14 Correct 29 ms 2296 KB Output is correct
15 Correct 30 ms 2296 KB Output is correct
16 Correct 32 ms 2296 KB Output is correct
17 Correct 21 ms 2296 KB Output is correct
18 Correct 26 ms 2428 KB Output is correct
19 Correct 28 ms 2424 KB Output is correct
20 Correct 32 ms 2296 KB Output is correct
21 Correct 60 ms 2368 KB Output is correct
22 Correct 68 ms 2300 KB Output is correct
23 Correct 48 ms 2372 KB Output is correct
24 Correct 86 ms 2296 KB Output is correct
25 Correct 86 ms 2392 KB Output is correct
26 Correct 92 ms 2400 KB Output is correct
27 Correct 90 ms 2424 KB Output is correct
28 Correct 90 ms 2424 KB Output is correct
29 Correct 91 ms 2468 KB Output is correct
30 Correct 89 ms 2296 KB Output is correct
31 Correct 91 ms 2428 KB Output is correct
32 Correct 90 ms 2296 KB Output is correct
33 Correct 90 ms 2424 KB Output is correct
34 Correct 90 ms 2424 KB Output is correct
35 Correct 90 ms 2296 KB Output is correct
36 Correct 92 ms 2532 KB Output is correct
37 Correct 180 ms 2648 KB Output is correct
38 Correct 180 ms 2592 KB Output is correct
39 Correct 229 ms 2680 KB Output is correct
40 Correct 250 ms 2808 KB Output is correct
41 Correct 254 ms 2552 KB Output is correct
42 Correct 231 ms 2612 KB Output is correct
43 Correct 242 ms 3064 KB Output is correct
44 Correct 240 ms 2988 KB Output is correct
45 Correct 241 ms 2936 KB Output is correct
46 Correct 241 ms 2424 KB Output is correct
47 Correct 232 ms 2680 KB Output is correct
48 Correct 241 ms 2948 KB Output is correct
49 Correct 240 ms 2680 KB Output is correct
50 Correct 231 ms 2684 KB Output is correct
51 Correct 73 ms 1500 KB Output is correct
52 Correct 269 ms 3036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 10 ms 2296 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 15 ms 2296 KB Output is correct
6 Correct 12 ms 2296 KB Output is correct
7 Correct 10 ms 2296 KB Output is correct
8 Correct 15 ms 2296 KB Output is correct
9 Correct 13 ms 2296 KB Output is correct
10 Correct 31 ms 2296 KB Output is correct
11 Correct 32 ms 2296 KB Output is correct
12 Correct 30 ms 2296 KB Output is correct
13 Correct 27 ms 2296 KB Output is correct
14 Correct 29 ms 2296 KB Output is correct
15 Correct 30 ms 2296 KB Output is correct
16 Correct 32 ms 2296 KB Output is correct
17 Correct 21 ms 2296 KB Output is correct
18 Correct 26 ms 2428 KB Output is correct
19 Correct 28 ms 2424 KB Output is correct
20 Correct 32 ms 2296 KB Output is correct
21 Correct 60 ms 2368 KB Output is correct
22 Correct 68 ms 2300 KB Output is correct
23 Correct 48 ms 2372 KB Output is correct
24 Correct 86 ms 2296 KB Output is correct
25 Correct 86 ms 2392 KB Output is correct
26 Correct 92 ms 2400 KB Output is correct
27 Correct 90 ms 2424 KB Output is correct
28 Correct 90 ms 2424 KB Output is correct
29 Correct 91 ms 2468 KB Output is correct
30 Correct 89 ms 2296 KB Output is correct
31 Correct 91 ms 2428 KB Output is correct
32 Correct 90 ms 2296 KB Output is correct
33 Correct 90 ms 2424 KB Output is correct
34 Correct 90 ms 2424 KB Output is correct
35 Correct 90 ms 2296 KB Output is correct
36 Correct 92 ms 2532 KB Output is correct
37 Correct 180 ms 2648 KB Output is correct
38 Correct 180 ms 2592 KB Output is correct
39 Correct 229 ms 2680 KB Output is correct
40 Correct 250 ms 2808 KB Output is correct
41 Correct 254 ms 2552 KB Output is correct
42 Correct 231 ms 2612 KB Output is correct
43 Correct 242 ms 3064 KB Output is correct
44 Correct 240 ms 2988 KB Output is correct
45 Correct 241 ms 2936 KB Output is correct
46 Correct 241 ms 2424 KB Output is correct
47 Correct 232 ms 2680 KB Output is correct
48 Correct 241 ms 2948 KB Output is correct
49 Correct 240 ms 2680 KB Output is correct
50 Correct 231 ms 2684 KB Output is correct
51 Correct 73 ms 1500 KB Output is correct
52 Correct 269 ms 3036 KB Output is correct
53 Correct 285 ms 2780 KB Output is correct
54 Correct 335 ms 3064 KB Output is correct
55 Correct 369 ms 3464 KB Output is correct
56 Correct 296 ms 2988 KB Output is correct
57 Correct 375 ms 3576 KB Output is correct
58 Correct 340 ms 3064 KB Output is correct
59 Correct 352 ms 3192 KB Output is correct
60 Correct 101 ms 1400 KB Output is correct
61 Correct 354 ms 3320 KB Output is correct
62 Correct 330 ms 3320 KB Output is correct
63 Correct 335 ms 3320 KB Output is correct
64 Correct 332 ms 3324 KB Output is correct
65 Correct 294 ms 2680 KB Output is correct
66 Correct 285 ms 2592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2296 KB Output is correct
2 Correct 10 ms 2296 KB Output is correct
3 Correct 4 ms 1272 KB Output is correct
4 Correct 8 ms 2296 KB Output is correct
5 Correct 15 ms 2296 KB Output is correct
6 Correct 12 ms 2296 KB Output is correct
7 Correct 10 ms 2296 KB Output is correct
8 Correct 15 ms 2296 KB Output is correct
9 Correct 13 ms 2296 KB Output is correct
10 Correct 31 ms 2296 KB Output is correct
11 Correct 32 ms 2296 KB Output is correct
12 Correct 30 ms 2296 KB Output is correct
13 Correct 27 ms 2296 KB Output is correct
14 Correct 29 ms 2296 KB Output is correct
15 Correct 30 ms 2296 KB Output is correct
16 Correct 32 ms 2296 KB Output is correct
17 Correct 21 ms 2296 KB Output is correct
18 Correct 26 ms 2428 KB Output is correct
19 Correct 28 ms 2424 KB Output is correct
20 Correct 32 ms 2296 KB Output is correct
21 Correct 60 ms 2368 KB Output is correct
22 Correct 68 ms 2300 KB Output is correct
23 Correct 48 ms 2372 KB Output is correct
24 Correct 86 ms 2296 KB Output is correct
25 Correct 86 ms 2392 KB Output is correct
26 Correct 92 ms 2400 KB Output is correct
27 Correct 90 ms 2424 KB Output is correct
28 Correct 90 ms 2424 KB Output is correct
29 Correct 91 ms 2468 KB Output is correct
30 Correct 89 ms 2296 KB Output is correct
31 Correct 91 ms 2428 KB Output is correct
32 Correct 90 ms 2296 KB Output is correct
33 Correct 90 ms 2424 KB Output is correct
34 Correct 90 ms 2424 KB Output is correct
35 Correct 90 ms 2296 KB Output is correct
36 Correct 92 ms 2532 KB Output is correct
37 Correct 180 ms 2648 KB Output is correct
38 Correct 180 ms 2592 KB Output is correct
39 Correct 229 ms 2680 KB Output is correct
40 Correct 250 ms 2808 KB Output is correct
41 Correct 254 ms 2552 KB Output is correct
42 Correct 231 ms 2612 KB Output is correct
43 Correct 242 ms 3064 KB Output is correct
44 Correct 240 ms 2988 KB Output is correct
45 Correct 241 ms 2936 KB Output is correct
46 Correct 241 ms 2424 KB Output is correct
47 Correct 232 ms 2680 KB Output is correct
48 Correct 241 ms 2948 KB Output is correct
49 Correct 240 ms 2680 KB Output is correct
50 Correct 231 ms 2684 KB Output is correct
51 Correct 73 ms 1500 KB Output is correct
52 Correct 269 ms 3036 KB Output is correct
53 Correct 285 ms 2780 KB Output is correct
54 Correct 335 ms 3064 KB Output is correct
55 Correct 369 ms 3464 KB Output is correct
56 Correct 296 ms 2988 KB Output is correct
57 Correct 375 ms 3576 KB Output is correct
58 Correct 340 ms 3064 KB Output is correct
59 Correct 352 ms 3192 KB Output is correct
60 Correct 101 ms 1400 KB Output is correct
61 Correct 354 ms 3320 KB Output is correct
62 Correct 330 ms 3320 KB Output is correct
63 Correct 335 ms 3320 KB Output is correct
64 Correct 332 ms 3324 KB Output is correct
65 Correct 294 ms 2680 KB Output is correct
66 Correct 285 ms 2592 KB Output is correct
67 Correct 401 ms 3204 KB Output is correct
68 Correct 142 ms 1272 KB Output is correct
69 Correct 625 ms 4476 KB Output is correct
70 Correct 573 ms 3704 KB Output is correct
71 Correct 544 ms 3704 KB Output is correct
72 Correct 534 ms 2908 KB Output is correct
73 Correct 532 ms 2936 KB Output is correct
74 Correct 634 ms 4508 KB Output is correct
75 Correct 583 ms 4084 KB Output is correct
76 Correct 642 ms 4468 KB Output is correct
77 Correct 651 ms 4596 KB Output is correct