Submission #890119

# Submission time Handle Problem Language Result Execution time Memory
890119 2023-12-20T14:57:58 Z kim Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 848 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define eb emplace_back

const int MX=50000;

int a[1005];
bool ok[1005][1005],flag[MX+5];

void solve(){
	int n; cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		for(int j=i+1;j<=n;++j) ok[i][j]=0;
	}
	for(int i=1;i<n;++i){
		if(a[i]>MX) continue;
		for(int j=1;j<=MX;++j) flag[j]=0;
		int sum=a[i];
		flag[a[i]]=1;
		for(int j=i+1;j<=n;++j){
			for(int k=min(sum,MX-a[j]);k>=1;--k) if(flag[k]) flag[k+a[j]]=1;
			sum+=a[j];
			if(!(sum&1)&&flag[sum>>1]) ok[i][j]=1;
		}
	}
	vector<int> ans;
	for(int i=2;i<=n;++i){
		bool ok2=1;
		for(int l=1,r=i;ok2&&r<=n;++l,++r){
			if(!ok[l][r]) ok2=0;
		}
		if(ok2) ans.eb(i);
	}
	cout<<ans.size()<<" ";
	for(auto &e:ans) cout<<e<<" ";
	cout<<endl;

}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int Q(1);
	cin>>Q;
	while(Q--){
		solve();
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 348 KB Output is correct
2 Correct 273 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2068 ms 848 KB Time limit exceeded
2 Halted 0 ms 0 KB -