제출 #539045

#제출 시각아이디문제언어결과실행 시간메모리
539045ddy888Kpart (eJOI21_kpart)C++17
30 / 100
2096 ms606372 KiB
#undef _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define int long long #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) int T; int N; signed main() { fast; cin >> T; while (T--) { cin >> N; vector<int> A(N + 1), ps(N + 1); int lim = 0; for (int i = 1; i <= N; ++i) { cin >> A[i]; ps[i] = ps[i - 1] + A[i]; lim += A[i]; } vector<vector<int> > dp(N + 1, vector<int>(lim + 1)); for (int en = 1; en <= N; ++en) { dp[en][0] = en; if (A[en] <= lim / 2 + 1) dp[en][A[en]] = en; for (int value = 1; value <= lim / 2 + 1; ++value) { if (value >= A[en]) dp[en][value] = max(dp[en - 1][value - A[en]], dp[en - 1][value]); else dp[en][value] = dp[en - 1][value]; } } vector<int> can(N + 1, 1); for (int i = 1; i <= N; ++i) { for (int j = i; j <= N; ++j) { int sum = ps[j] - ps[i - 1]; if (sum % 2 != 0) can[j - i + 1] = 0; else if (dp[j][sum / 2] < i) can[j - i + 1] = 0; } } vector<int> ans; for (int i = 1; i <= N; ++i) { if (can[i]) ans.pb(i); } cout << (int)ans.size() << ' '; for (auto i: ans) cout << i << ' '; cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...