Submission #765907

# Submission time Handle Problem Language Result Execution time Memory
765907 2023-06-25T07:19:22 Z vjudge1 Kpart (eJOI21_kpart) C++17
0 / 100
2000 ms 176088 KB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define len(x) (int)x.size()
#define ull unsigned long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define int long long

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
int t,n,a[N],dp[N],p[N];
vector <int> ans,v,vv;
set <int> st;
map <int,int> mp;

main(){
	// freopen("txt.in", "r", stdin);
	// freopen("txt.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> t;
	while(t--){
		cin >> n;
		for (int i=1;i<=n;i++){
			cin >> a[i];
			p[i] = p[i-1] + a[i];
		}
		for (int i=2;i<=n;i++){
			bool ok = 1;
			for (int j=i;j<=n;j++){
				if ((p[j] - p[j-i]) % 2 == 1){
					ok = 0;
					break;
				}
				v.clear();
				v.pb(0);
				for (int k=j-i+1;k<=j;k++){
					for (auto it : v){
						if (it + a[k] <= (p[j] - p[j-i])/2){
							vv.pb((it + a[k]));
						}
					}
					for (auto it : vv){
						v.pb(it);
					}
					vv.clear();
				}
				sort(v.begin(),v.end());
				if (v.back() != (p[j]-p[j-i])/2){
					ok = 0;
					break;	
				}
			}
			if (ok){
				ans.pb(i);
			}
		}
		cout << len(ans) << ' ';
		for (auto it : ans){
			cout << it << ' ';
		} cout << '\n';\
		ans.clear();
		mp.clear();
		st.clear();
	}
}

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).

//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)

//a/b%mod = a*(b^(m-2)%mod)
//(a>>x)&1 == 0
//a^b = (a+b)-2(a&b)

//srand(time(0))-always changing

Compilation message

Main.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 176088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2060 ms 48100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 10228 KB Time limit exceeded
2 Halted 0 ms 0 KB -