Submission #602866

# Submission time Handle Problem Language Result Execution time Memory
602866 2022-07-23T11:58:10 Z dozer Kpart (eJOI21_kpart) C++14
100 / 100
1867 ms 391744 KB
#include <bits/stdc++.h>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define endl "\n"
#define sp " "
#define st first
#define nd second
#define N 1005
#define M 100005
#define modulo 1000000007


int dp[N][M];
int arr[N], pre[N];

int main()
{
	fastio();

	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for (int i = 1; i <= n; i++)
		{
			cin>>arr[i];
			pre[i] = pre[i - 1] + arr[i];
		}

		for (int i = 0; i <= pre[n]; i++)
			dp[0][i] = 0;
		for (int i = 1; i <= n; i++)
		{
			for (int j = pre[n] - arr[i]; j > 0; j--)
			{
				dp[i][j + arr[i]] =  max(dp[i - 1][j + arr[i]], dp[i - 1][j]);
			}
			dp[i][arr[i]] = i;
			for (int j = arr[i] - 1; j > 0; j--) dp[i][j] = dp[i - 1][j];
		}

		vector<int> ans;
		for (int i = 2; i <= n; i++)
		{
			int flag = 1;
			for (int j = 1; j <= n - i + 1; j++)
			{
				int sum = pre[j + i - 1] - pre[j - 1];
				if (sum % 2 == 1 || dp[j + i - 1][sum / 2] < j) flag = 0;
				//if (sum % 2 == 0) cout<<j + i - 1<<sp<<sum / 2<<sp<<dp[j + i - 1][sum / 2]<<endl;
			}
			if (flag == 1) ans.pb(i);
		}
		cout<<ans.size()<<sp;
		for (auto i : ans) cout<<i<<sp;
		cout<<endl;
	}
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2644 KB Output is correct
2 Correct 25 ms 7056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 27400 KB Output is correct
2 Correct 283 ms 61576 KB Output is correct
3 Correct 341 ms 78372 KB Output is correct
4 Correct 575 ms 130996 KB Output is correct
5 Correct 1336 ms 321204 KB Output is correct
6 Correct 1867 ms 386000 KB Output is correct
7 Correct 1700 ms 391744 KB Output is correct