답안 #514683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
514683 2022-01-18T10:57:22 Z Mazaalai Bootfall (IZhO17_bootfall) C++17
13 / 100
90 ms 2268 KB
#include <bits/stdc++.h>
#define pb push_back
#define LINE "-------------------\n"
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int N = 500+1;
const int M = 500*500+1;
vector <int> ans;
int n, m, nums[N];
const ll MOD = 1e9+7;
ll dp[M], dp1[M], sum;
signed main() {

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> nums[i];
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		int& x = nums[i];
		sum += x;
		for (int j = M-1; j >= x; j--) 
			dp[j] = (dp[j] + dp[j-x]) % MOD;
	}
	// for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10];
	if (sum & 1 || dp[sum / 2] == 0) {
		cout << "0\n";
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		int& x = nums[i];
		for (int j = x; j <= M-1; j++) 
			dp[j] = (dp[j] - dp[j-x]) % MOD;
		/* 
			left = (sum - x + a) / 2 == j;
			sum-x+a = 2j
			a = 2j+x-sum;
		*/
		// cout << LINE;B
		// cout << x << ":\n";
		// cout << "dp: ";
		// for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10];
		for (int j = M-1; j >= 0; j--) {
			int a = 2 * j + x - sum;
			if (dp[j] > 0 && a >= 0) {
				dp1[a]++;
				// cout << 2 * j + x - sum << ' ';
			}
		}
		
		// cout << "\n";
		for (int j = M-1; j >= x; j--) 
			dp[j] = (dp[j] + dp[j-x]) % MOD;

		// cout << "dp: ";
		// for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10];
	}
	for (int j = 0; j < M; j++) {
		if (dp1[j] == n) ans.pb(j);
	}
	cout << sz(ans) << '\n';
	for (auto&el:ans) cout << el << ' '; cout << '\n';
}


















Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:63:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   63 |  for (auto&el:ans) cout << el << ' '; cout << '\n';
      |  ^~~
bootfall.cpp:63:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   63 |  for (auto&el:ans) cout << el << ' '; cout << '\n';
      |                                       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2252 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 9 ms 2264 KB Output is correct
5 Correct 19 ms 2220 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 10 ms 2252 KB Output is correct
8 Correct 18 ms 2268 KB Output is correct
9 Correct 16 ms 2264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2252 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 9 ms 2264 KB Output is correct
5 Correct 19 ms 2220 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 10 ms 2252 KB Output is correct
8 Correct 18 ms 2268 KB Output is correct
9 Correct 16 ms 2264 KB Output is correct
10 Correct 52 ms 2264 KB Output is correct
11 Correct 46 ms 2252 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 39 ms 2252 KB Output is correct
14 Correct 39 ms 2220 KB Output is correct
15 Correct 43 ms 2252 KB Output is correct
16 Correct 50 ms 2240 KB Output is correct
17 Correct 28 ms 2252 KB Output is correct
18 Correct 45 ms 2252 KB Output is correct
19 Correct 38 ms 2252 KB Output is correct
20 Correct 41 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2252 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 9 ms 2264 KB Output is correct
5 Correct 19 ms 2220 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 10 ms 2252 KB Output is correct
8 Correct 18 ms 2268 KB Output is correct
9 Correct 16 ms 2264 KB Output is correct
10 Correct 52 ms 2264 KB Output is correct
11 Correct 46 ms 2252 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 39 ms 2252 KB Output is correct
14 Correct 39 ms 2220 KB Output is correct
15 Correct 43 ms 2252 KB Output is correct
16 Correct 50 ms 2240 KB Output is correct
17 Correct 28 ms 2252 KB Output is correct
18 Correct 45 ms 2252 KB Output is correct
19 Correct 38 ms 2252 KB Output is correct
20 Correct 41 ms 2252 KB Output is correct
21 Incorrect 90 ms 2260 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2252 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 9 ms 2264 KB Output is correct
5 Correct 19 ms 2220 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 10 ms 2252 KB Output is correct
8 Correct 18 ms 2268 KB Output is correct
9 Correct 16 ms 2264 KB Output is correct
10 Correct 52 ms 2264 KB Output is correct
11 Correct 46 ms 2252 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 39 ms 2252 KB Output is correct
14 Correct 39 ms 2220 KB Output is correct
15 Correct 43 ms 2252 KB Output is correct
16 Correct 50 ms 2240 KB Output is correct
17 Correct 28 ms 2252 KB Output is correct
18 Correct 45 ms 2252 KB Output is correct
19 Correct 38 ms 2252 KB Output is correct
20 Correct 41 ms 2252 KB Output is correct
21 Incorrect 90 ms 2260 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2252 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 9 ms 2264 KB Output is correct
5 Correct 19 ms 2220 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 10 ms 2252 KB Output is correct
8 Correct 18 ms 2268 KB Output is correct
9 Correct 16 ms 2264 KB Output is correct
10 Correct 52 ms 2264 KB Output is correct
11 Correct 46 ms 2252 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 39 ms 2252 KB Output is correct
14 Correct 39 ms 2220 KB Output is correct
15 Correct 43 ms 2252 KB Output is correct
16 Correct 50 ms 2240 KB Output is correct
17 Correct 28 ms 2252 KB Output is correct
18 Correct 45 ms 2252 KB Output is correct
19 Correct 38 ms 2252 KB Output is correct
20 Correct 41 ms 2252 KB Output is correct
21 Incorrect 90 ms 2260 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2252 KB Output is correct
2 Correct 13 ms 2252 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 9 ms 2264 KB Output is correct
5 Correct 19 ms 2220 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 10 ms 2252 KB Output is correct
8 Correct 18 ms 2268 KB Output is correct
9 Correct 16 ms 2264 KB Output is correct
10 Correct 52 ms 2264 KB Output is correct
11 Correct 46 ms 2252 KB Output is correct
12 Correct 45 ms 2264 KB Output is correct
13 Correct 39 ms 2252 KB Output is correct
14 Correct 39 ms 2220 KB Output is correct
15 Correct 43 ms 2252 KB Output is correct
16 Correct 50 ms 2240 KB Output is correct
17 Correct 28 ms 2252 KB Output is correct
18 Correct 45 ms 2252 KB Output is correct
19 Correct 38 ms 2252 KB Output is correct
20 Correct 41 ms 2252 KB Output is correct
21 Incorrect 90 ms 2260 KB Output isn't correct
22 Halted 0 ms 0 KB -