답안 #676151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676151 2022-12-29T14:24:42 Z HamletPetrosyan Bootfall (IZhO17_bootfall) C++17
13 / 100
21 ms 1324 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int N = 1000, M = 122505;

ll n, a[N], sum = 0;
ll dp[N * N];
ll qn[N * N];

void solve(){
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i], sum += a[i];
	if(sum % 2 == 1){
		cout << "0\n";
		return;
	}
	dp[0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = M - a[i]; j >= 0; j--){
			dp[j + a[i]] += dp[j];
		}
	}
//	for(int i = 0; i <= M; i++) cout << dp[i] << " ";
//	cout << "\n";
	if(dp[sum / 2] == 0){
		cout << "0\n";
		return;
	}
	for(int i = 0; i < n; i++){
		sum -= a[i];
		for(int j = 0; j <= M - a[i]; j++){
			dp[j + a[i]] -= dp[j];
		}
//		cout << i << ": ";
//		for(int j = 0; j <= M; j++){
//			cout << dp[j] << " ";
//		}
//		cout << "\n";
		for(int j = 0, x; j <= M; j++){
			if(dp[j] > 0){
				x = abs(sum - j - j);
//				cout << j << " " << sum << " " << x << "\n";
				if(qn[x] == i) qn[x] = i + 1;
			}
		}
//		for(int j = 0; j <= M; j++){
//			cout << qn[j] << " ";
//		}
//		cout << "\n";
		sum += a[i];
		for(int j = M - a[i]; j >= 0; j--){
			dp[j + a[i]] += dp[j];
		}
	}
	ll cnt = 0;
	for(int i = 1; i <= M; i++){
		if(qn[i] == n) cnt++;
	}
	cout << cnt << "\n";
	for(int i = 1; i <= M; i++){
		if(qn[i] == n) cout << i << " ";
	}
	cout << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1304 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 3 ms 1300 KB Output is correct
7 Correct 3 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1304 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 3 ms 1300 KB Output is correct
7 Correct 3 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 9 ms 1236 KB Output is correct
11 Correct 10 ms 1224 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 8 ms 1296 KB Output is correct
14 Correct 9 ms 1300 KB Output is correct
15 Correct 10 ms 1312 KB Output is correct
16 Correct 10 ms 1236 KB Output is correct
17 Correct 6 ms 1296 KB Output is correct
18 Correct 8 ms 1224 KB Output is correct
19 Correct 8 ms 1236 KB Output is correct
20 Correct 10 ms 1304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1304 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 3 ms 1300 KB Output is correct
7 Correct 3 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 9 ms 1236 KB Output is correct
11 Correct 10 ms 1224 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 8 ms 1296 KB Output is correct
14 Correct 9 ms 1300 KB Output is correct
15 Correct 10 ms 1312 KB Output is correct
16 Correct 10 ms 1236 KB Output is correct
17 Correct 6 ms 1296 KB Output is correct
18 Correct 8 ms 1224 KB Output is correct
19 Correct 8 ms 1236 KB Output is correct
20 Correct 10 ms 1304 KB Output is correct
21 Correct 21 ms 1324 KB Output is correct
22 Incorrect 21 ms 1320 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1304 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 3 ms 1300 KB Output is correct
7 Correct 3 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 9 ms 1236 KB Output is correct
11 Correct 10 ms 1224 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 8 ms 1296 KB Output is correct
14 Correct 9 ms 1300 KB Output is correct
15 Correct 10 ms 1312 KB Output is correct
16 Correct 10 ms 1236 KB Output is correct
17 Correct 6 ms 1296 KB Output is correct
18 Correct 8 ms 1224 KB Output is correct
19 Correct 8 ms 1236 KB Output is correct
20 Correct 10 ms 1304 KB Output is correct
21 Correct 21 ms 1324 KB Output is correct
22 Incorrect 21 ms 1320 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1304 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 3 ms 1300 KB Output is correct
7 Correct 3 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 9 ms 1236 KB Output is correct
11 Correct 10 ms 1224 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 8 ms 1296 KB Output is correct
14 Correct 9 ms 1300 KB Output is correct
15 Correct 10 ms 1312 KB Output is correct
16 Correct 10 ms 1236 KB Output is correct
17 Correct 6 ms 1296 KB Output is correct
18 Correct 8 ms 1224 KB Output is correct
19 Correct 8 ms 1236 KB Output is correct
20 Correct 10 ms 1304 KB Output is correct
21 Correct 21 ms 1324 KB Output is correct
22 Incorrect 21 ms 1320 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1304 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 3 ms 1300 KB Output is correct
7 Correct 3 ms 1236 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 4 ms 1236 KB Output is correct
10 Correct 9 ms 1236 KB Output is correct
11 Correct 10 ms 1224 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 8 ms 1296 KB Output is correct
14 Correct 9 ms 1300 KB Output is correct
15 Correct 10 ms 1312 KB Output is correct
16 Correct 10 ms 1236 KB Output is correct
17 Correct 6 ms 1296 KB Output is correct
18 Correct 8 ms 1224 KB Output is correct
19 Correct 8 ms 1236 KB Output is correct
20 Correct 10 ms 1304 KB Output is correct
21 Correct 21 ms 1324 KB Output is correct
22 Incorrect 21 ms 1320 KB Output isn't correct
23 Halted 0 ms 0 KB -