Submission #1027888

#TimeUsernameProblemLanguageResultExecution timeMemory
1027888pubin06Kpart (eJOI21_kpart)C++14
100 / 100
466 ms860 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...