Submission #537443

# Submission time Handle Problem Language Result Execution time Memory
537443 2022-03-15T06:09:54 Z jamezzz Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 393836 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf

int t,n,a[1005],p[1005],memo[1005][100005],die[1005];

int dp(int i,int v){
	if(a[i]==v)return i;
	if(v<0||i==0)return 0;
	if(memo[i][v]!=-1)return memo[i][v];
	return memo[i][v]=max(dp(i-1,v),dp(i-1,v-a[i]));
}

int main(){
	sf("%d",&t);
	while(t--){
		sf("%d",&n);
		for(int i=1;i<=n;++i)sf("%d",&a[i]),p[i]=a[i]+p[i-1];
		memset(die,0,sizeof die);
		memset(memo,-1,sizeof memo);
		for(int i=1;i<=n;++i){
			for(int j=i;j<=n;++j){
				if(die[j-i+1])continue;
				if((p[j]-p[i-1])%2==1)die[j-i+1]=true;
				if(dp(j,(p[j]-p[i-1])/2)<i)die[j-i+1]=true;
			}
		}
		int cnt=0;
		for(int i=1;i<=n;++i)if(!die[i])++cnt;
		pf("%d ",cnt);
		for(int i=1;i<=n;++i)if(!die[i])pf("%d ",i);
		pf("\n");
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:17:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  sf("%d",&t);
      |    ^
Main.cpp:19:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   sf("%d",&n);
      |     ^
Main.cpp:20:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   for(int i=1;i<=n;++i)sf("%d",&a[i]),p[i]=a[i]+p[i-1];
      |                          ^
# Verdict Execution time Memory Grader output
1 Correct 899 ms 393660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 992 ms 393660 KB Output is correct
2 Correct 1070 ms 393544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1305 ms 393672 KB Output is correct
2 Execution timed out 2121 ms 393836 KB Time limit exceeded
3 Halted 0 ms 0 KB -