Submission #794199

#TimeUsernameProblemLanguageResultExecution timeMemory
794199Chal1shkanKpart (eJOI21_kpart)C++14
100 / 100
374 ms98080 KiB
//Bismillahir-Rahmanir-Rahim #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") # include <bits/stdc++.h> # define TIME (clock() * 1.0 / CLOCKS_PER_SEC) # define pb push_back # define ff first # define ss second # define nl "\n" # define sz(x) ((int)(x).size()) # define all(x) (x).begin(), (x).end() # define deb(x) cerr << #x << " = " << x << endl; # define pll pair <ll, ll> # define pii pair <int, int> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 1e5 + 7; const ll inf = 2e18 + 0; const ll mod = 1e9 + 7; const ll dx[] = {-1, 1, 0, 0}; const ll dy[] = {0, 0, -1, 1}; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); short n; int a[1003]; short dp[1003][50003]; int pref[1003]; bitset <1003> ans; void ma1n (/* SABR */) { cin >> n; for (short i = 1; i <= n; ++i) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } for (short i = 1; i <= n; ++i) { for (int j = 0; j <= pref[n] / 2; ++j) { dp[i][j] = 0; } } ans.reset(); for (short k = 2; k <= n; ++k) ans[k] = 1; for (short i = 1; i <= n; ++i) { for (int j = 1; j <= pref[n] / 2; ++j) { dp[i][j] = dp[i - 1][j]; if (j > a[i]) { dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]]); } else if (j == a[i]) { dp[i][j] = i; } } for (short k = 2; k <= i; ++k) { int sum = pref[i] - pref[i - k]; if (sum & 1) { ans[k] = 0; } if (dp[i][sum / 2] < i - k + 1) { ans[k] = 0; } } } cout << ans.count() << ' '; for(short i = ans._Find_first(); i <= n; i = ans._Find_next(i)) { cout << i << ' '; } cout << nl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); int ttt = 1; cin >> ttt; for (int test = 1; test <= ttt; ++test) { // cout << "Case " << test << ":" << '\n'; ma1n(); } return 0; } // 998batrr | BbIWEJI 3A TObOU!!! // tourist | BbIWEJI 3A TObOU!!!
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...