Submission #632460

# Submission time Handle Problem Language Result Execution time Memory
632460 2022-08-20T05:39:12 Z pragmatist Kpart (eJOI21_kpart) C++17
10 / 100
2000 ms 340 KB
#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)31;
const int M = (int)1e5 + 7; 

int n, a[N];
bitset<M> dp; 

void solve() {
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	vector<int> ans;
	for(int k = 2; k <= n; ++k) {
		bool ok = 1;
		for(int i = 1; i <= n - k + 1; ++i) {
			dp.reset();
			dp[0] = 1;
			bool cur = 0;
		    int sum = 0;
			for(int j = i; j <= i + k - 1; ++j) {
				sum += a[j];
				dp |= dp << a[j];
			}
			if(sum & 1) {
				ok = 0;
				break;
			}
			if(!dp[sum / 2]) {
				ok = 0;
				break;	
			}
		}          
		if(ok) ans.pb(k);
	}
	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;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:25:9: warning: unused variable 'cur' [-Wunused-variable]
   25 |    bool cur = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 70 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2063 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -