| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1308029 | nanaseyuzuki | Kpart (eJOI21_kpart) | C++20 | 1159 ms | 9192 KiB |
#include <bits/stdc++.h>
// Kazusa_Megumi
#define ll long long
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
const int mn = 1e3 + 5, mod = 1e9 + 7, inf = 2e9;
int m, n, x, y, a[mn];
int dp[100005], f[mn][mn], prefix[mn], tmp[mn];
void clear(){
memset(f, 1, sizeof(f));
memset(dp, 0, sizeof(dp));
memset(prefix, 0, sizeof(prefix));
}
void solve(){
clear();
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
prefix[i] = prefix[i - 1] + a[i];
}
for(int i = 1; i <= n; i++){
for(int s = 1e5; s >= a[i]; s--){
if(dp[s - a[i]] != 0) dp[s] = max(dp[s], dp[s - a[i]]);
}
dp[a[i]] = i;
for(int k = 1; k <= i; k++){
if((prefix[i] - prefix[k - 1]) % 2 != 0){
f[i][i - k + 1] = 0;
continue;
}
int qq = 0;
if((dp[(prefix[i] - prefix[k - 1]) / 2] >= k)) qq = 1;
if(i > k) f[i][i - k + 1] = min(f[i - 1][i - k + 1], qq);
else if(i == k) f[i][i - k + 1] = qq;
}
}
vector <int> res;
for(int i = 1; i <= n; i++){
if(f[n][i]) res.push_back(i);
}
cout << res.size() << ' ';
for(auto i : res) cout << i << ' ';
cout << '\n';
}
main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
if (fopen("Kazuki.INP", "r")) {
freopen("Kazuki.INP", "r", stdin);
freopen("Kazuki.OUT", "w", stdout);
}
int t = 1;
cin >> t;
while (t--) solve();
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... | ||||
