# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1263546 | tminh | Kpart (eJOI21_kpart) | C++20 | 1039 ms | 876 KiB |
#include "bits/stdc++.h"
using namespace std;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const ll oo = 1e18;
bool START;
int n, t, sum, a[1005], pre[1005];
int dp[N];
bool ans[1005];
int get(int l, int r) {
return pre[r] - pre[l - 1];
}
inline void solve() {
for (int i = 1; i <= n; ++i) ans[i] = true;
for (int i = 1; i <= n; ++i) {
for (int j = sum; j >= a[i]; --j) dp[j] = max(dp[j], dp[j - a[i]]);
dp[a[i]] = i;
for (int j = 1; j <= i; ++j) {
if (get(j, i) & 1) {
ans[i - j + 1] = false;
continue;
}
ans[i - j + 1] &= (dp[get(j, i) >> 1] >= j);
}
}
vector<int> res;
for (int i = 1; i <= n; ++i) {
if (ans[i]) res.pb(i);
ans[i] = 0;
}
for (int i = 0; i <= sum; ++i) dp[i] = 0;
cout << sze(res) << " ";
for (int i : res) cout << i << " ";
cout << endl;
}
inline void input() {
cin >> n;
sum = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i];
pre[i] = pre[i - 1] + a[i];
}
return solve();
}
bool END;
int main() {
if(fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> t;
while(t--) input();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |