답안 #1027888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027888 2024-07-19T10:56:11 Z pubin06 Kpart (eJOI21_kpart) C++14
100 / 100
466 ms 860 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(v) (int)(v).size()
using namespace std;
 
const int MXn = 100005;
 
int n, a[1003], prf[1003];
int dp[MXn];
bool ok[1003];
long long tot = 0;
void solve(void) {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		prf[i] = prf[i - 1] + a[i];
	}
	memset(dp, -1, sizeof dp);
	memset(ok, true, sizeof ok);
	int cur = 0;
	for (int i = 1; i <= n; i++) {
		tot += cur;
		for (int s = cur; s > 0; s--) {
			dp[s + a[i]] = max(dp[s + a[i]], dp[s]);
		}
		dp[a[i]] = i;
		cur += a[i];
		for (int j = 1; j <= i; j++) {
			if ((prf[i] - prf[j - 1]) % 2 || dp[(prf[i] - prf[j - 1]) / 2] < j) {
				ok[i - j + 1] = false;
			}
		}
	}
	vector<int> K;
	for (int len = 1; len <= n; len++) if (ok[len]) {
		K.emplace_back(len);
	}
	cout << sz(K) << ' ';
	for (int len: K) cout << len << ' ';
	cout << '\n';
}
 
signed main(void) {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	int T; cin >> T; while (T--) solve();
	if (tot >= 1000000000) cout << "hai code";
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 860 KB Output is correct
2 Correct 69 ms 856 KB Output is correct
3 Correct 101 ms 860 KB Output is correct
4 Correct 145 ms 856 KB Output is correct
5 Correct 328 ms 852 KB Output is correct
6 Correct 466 ms 836 KB Output is correct
7 Correct 418 ms 856 KB Output is correct