Submission #1032053

#TimeUsernameProblemLanguageResultExecution timeMemory
1032053ten_xdKpart (eJOI21_kpart)C++17
100 / 100
1308 ms1244 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define rep(a,b) for(int a = 0; a < (b); ++a) #define all(t) t.begin(), t.end() #define pb push_back const int N = 1005, INF = 2e9+54321; const ll INF_L = (ll)2e18+54321; int n,s; int A[N]; vector<bool> wyn; vector<int> dp; void solve() { cin >> n; rep(i,n) cin >> A[i]; wyn.assign(n+1,1), s = 0; rep(i,n) s += A[i]; dp.assign(s+1,-1); rep(i,n) { for(int j = s; j > A[i]; --j) dp[j] = max(dp[j],dp[j-A[i]]); dp[A[i]] = i; int su = 0; for(int j = i; j >= 0; --j) { su += A[j]; int len = i-j+1; if(su % 2 == 1 or dp[su/2] < j) wyn[len] = 0; } } vector<int> re; for(int i = 1; i <= n; ++i) if(wyn[i]) re.pb(i); cout << (int)re.size() << ' '; for(auto x : re) cout << x << ' '; cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; cin >> T; while(T--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...