제출 #632637

#제출 시각아이디문제언어결과실행 시간메모리
632637pragmatistKpart (eJOI21_kpart)C++17
30 / 100
2077 ms2280 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define sz(v) (int)v.size() #define nl "\n" using namespace std; const int N = (int)1e3 + 7; const int MOD = (int)1e9 + 7; const int M = (int)5e5 + 7; int n, a[N], dp[M], lst[M]; bool ok[N]; void solve() { cin >> n; for(int i = 1; i <= n; ++i) cin >> a[i]; fill(ok + 1, ok + 1 + n, 1); fill(lst, lst + M, -1); for(int i = 1; i <= n; ++i) { for(int w = M - a[i] - 1; w >= 0; --w) { if(lst[w] != -1) lst[w + a[i]] = max(lst[w + a[i]], lst[w]); } lst[a[i]] = i; int sum = 0; for(int j = i; j >= 1; --j) { sum += a[j]; if(sum & 1) { ok[i - j + 1] = 0; } else { if(lst[sum / 2] < j) ok[i - j + 1] = 0; } } } vector<int> ans; for(int i = 1; i <= n; ++i) if(ok[i]) ans.pb(i); cout << sz(ans) << ' '; for(auto x : ans) cout << x << ' '; cout << nl; } int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int test; cin >> test; while(test--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...