답안 #168455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168455 2019-12-13T06:54:16 Z Gurban Bootfall (IZhO17_bootfall) C++14
100 / 100
429 ms 3944 KB
#include <bits/stdc++.h>

#define pb push_back
#define ss second
#define ff first
#define N 250009
#define inf 1000000009
#define ll long long
#define mid(a,b) (a+b)/2

using namespace std;

int n,a[509],sum,dp[N],s;
vector <int> v,ans;

const int mod = 1e9+7;

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		sum += a[i];
	}
	dp[0] = 1;
	for(int i = 1;i <= n;i++)
		for(int j = sum;j >= 0;j--)
			dp[j + a[i]] += dp[j];
		
	if(sum % 2 == 1 or  dp[sum / 2] == 0)
		return cout << 0,0;
	
	
	for(int i = 1;i <= sum;i++)
		ans.pb(i);
	
	for(int i = 1;i <= n;i++){
		for(int j = a[i];j <= sum;j++)
			dp[j] -= dp[j - a[i]];
		
		for(auto j : ans){
			s = sum - a[i] + j;
			if(s % 2 == 0 and s / 2 - j >= 0 and dp[s / 2 - j])
				v.pb(j);
		}
		
		ans.clear();
		ans = v;
		v.clear();
		
		for(int j = sum;j >= a[i];j--)
			dp[j] += dp[j - a[i]];
	}
	printf("%d\n",ans.size());
	for(auto i : ans) printf("%d\n",i);
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:54:26: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n",ans.size());
                ~~~~~~~~~~^
bootfall.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
bootfall.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 508 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 508 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 24 ms 632 KB Output is correct
38 Correct 17 ms 632 KB Output is correct
39 Correct 32 ms 888 KB Output is correct
40 Correct 36 ms 888 KB Output is correct
41 Correct 40 ms 1268 KB Output is correct
42 Correct 30 ms 888 KB Output is correct
43 Correct 52 ms 1140 KB Output is correct
44 Correct 53 ms 1184 KB Output is correct
45 Correct 54 ms 1136 KB Output is correct
46 Correct 19 ms 632 KB Output is correct
47 Correct 33 ms 888 KB Output is correct
48 Correct 49 ms 1140 KB Output is correct
49 Correct 36 ms 1016 KB Output is correct
50 Correct 33 ms 760 KB Output is correct
51 Correct 7 ms 376 KB Output is correct
52 Correct 68 ms 1392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 508 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 24 ms 632 KB Output is correct
38 Correct 17 ms 632 KB Output is correct
39 Correct 32 ms 888 KB Output is correct
40 Correct 36 ms 888 KB Output is correct
41 Correct 40 ms 1268 KB Output is correct
42 Correct 30 ms 888 KB Output is correct
43 Correct 52 ms 1140 KB Output is correct
44 Correct 53 ms 1184 KB Output is correct
45 Correct 54 ms 1136 KB Output is correct
46 Correct 19 ms 632 KB Output is correct
47 Correct 33 ms 888 KB Output is correct
48 Correct 49 ms 1140 KB Output is correct
49 Correct 36 ms 1016 KB Output is correct
50 Correct 33 ms 760 KB Output is correct
51 Correct 7 ms 376 KB Output is correct
52 Correct 68 ms 1392 KB Output is correct
53 Correct 53 ms 996 KB Output is correct
54 Correct 75 ms 1192 KB Output is correct
55 Correct 139 ms 2068 KB Output is correct
56 Correct 67 ms 1128 KB Output is correct
57 Correct 149 ms 2032 KB Output is correct
58 Correct 84 ms 1268 KB Output is correct
59 Correct 103 ms 1552 KB Output is correct
60 Correct 16 ms 504 KB Output is correct
61 Correct 114 ms 1680 KB Output is correct
62 Correct 116 ms 1904 KB Output is correct
63 Correct 124 ms 1904 KB Output is correct
64 Correct 120 ms 1908 KB Output is correct
65 Correct 32 ms 888 KB Output is correct
66 Correct 40 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 508 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 24 ms 632 KB Output is correct
38 Correct 17 ms 632 KB Output is correct
39 Correct 32 ms 888 KB Output is correct
40 Correct 36 ms 888 KB Output is correct
41 Correct 40 ms 1268 KB Output is correct
42 Correct 30 ms 888 KB Output is correct
43 Correct 52 ms 1140 KB Output is correct
44 Correct 53 ms 1184 KB Output is correct
45 Correct 54 ms 1136 KB Output is correct
46 Correct 19 ms 632 KB Output is correct
47 Correct 33 ms 888 KB Output is correct
48 Correct 49 ms 1140 KB Output is correct
49 Correct 36 ms 1016 KB Output is correct
50 Correct 33 ms 760 KB Output is correct
51 Correct 7 ms 376 KB Output is correct
52 Correct 68 ms 1392 KB Output is correct
53 Correct 53 ms 996 KB Output is correct
54 Correct 75 ms 1192 KB Output is correct
55 Correct 139 ms 2068 KB Output is correct
56 Correct 67 ms 1128 KB Output is correct
57 Correct 149 ms 2032 KB Output is correct
58 Correct 84 ms 1268 KB Output is correct
59 Correct 103 ms 1552 KB Output is correct
60 Correct 16 ms 504 KB Output is correct
61 Correct 114 ms 1680 KB Output is correct
62 Correct 116 ms 1904 KB Output is correct
63 Correct 124 ms 1904 KB Output is correct
64 Correct 120 ms 1908 KB Output is correct
65 Correct 32 ms 888 KB Output is correct
66 Correct 40 ms 1016 KB Output is correct
67 Correct 122 ms 1568 KB Output is correct
68 Correct 41 ms 888 KB Output is correct
69 Correct 385 ms 3600 KB Output is correct
70 Correct 239 ms 2284 KB Output is correct
71 Correct 232 ms 2256 KB Output is correct
72 Correct 122 ms 1904 KB Output is correct
73 Correct 120 ms 1876 KB Output is correct
74 Correct 411 ms 3816 KB Output is correct
75 Correct 324 ms 3304 KB Output is correct
76 Correct 423 ms 3840 KB Output is correct
77 Correct 429 ms 3944 KB Output is correct