Submission #1032054

# Submission time Handle Problem Language Result Execution time Memory
1032054 2024-07-23T10:39:37 Z ten_xd Kpart (eJOI21_kpart) C++17
100 / 100
627 ms 1248 KB
    #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);
     
    	int at = 0;
    	rep(i,n)
    	{
    		at += A[i];
    		for(int j = at; 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 time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 10 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 936 KB Output is correct
2 Correct 105 ms 800 KB Output is correct
3 Correct 111 ms 760 KB Output is correct
4 Correct 239 ms 860 KB Output is correct
5 Correct 449 ms 1120 KB Output is correct
6 Correct 627 ms 1248 KB Output is correct
7 Correct 584 ms 1104 KB Output is correct