Submission #499814

# Submission time Handle Problem Language Result Execution time Memory
499814 2021-12-29T15:31:26 Z luka1234 Bootfall (IZhO17_bootfall) C++14
0 / 100
5 ms 292 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
int findmin(int a[],int n){
	int sum=0;
	for(int k=1;k<=n;k++){
		sum+=a[k];
	}
	bool dp[n+1][sum+1];
	for(int k=1;k<=n;k++){
		dp[k][0]=1;
	}
	for(int k=1;k<=sum;k++){
		dp[0][k]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=sum;j++){
			dp[i][j]=dp[i-1][j];
			if(dp[i][j]==1)
			   continue;
			if(j>=a[i])
			   dp[i][j]=dp[i-1][j-a[i]];
			else
			   dp[i][j]=0;
		}
	}
	int diff=1e9;
	for(int k=sum/2;k>=0;k--){
		if(dp[n][k]==1){
			diff=sum-k*2;
			break;
		}
	}
	return diff;
}
int main(){
	int n;
	cin>>n;
	int a[n+1];
	int a1[n+2];
	int a2[n+2];
	for(int k=1;k<=n;k++){
		cin>>a[k];
		a1[k+1]=a[k];
		a2[k+1]=a[k];
	}
	vector<int> ans;
	for(int k=1;k<=500;k++){
		a1[1]=k;
		a2[1]=k;
		int ind=0;
		for(int i=1;i<=n+1;i++){
			a2[i]=0;
			int diff=findmin(a2,n+1);
			a2[i]=a1[i];
			if(diff!=0){
				ind=1;
				break;
			}
		}
		if(ind==0)
		   ans.push_back(k);
	}
	cout<<ans.size()<<"\n";
	for(int k=0;k<ans.size();k++)
	    cout<<ans[k]<<' ';
	return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:67:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int k=0;k<ans.size();k++)
      |              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 5 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 5 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 5 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 5 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 5 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 5 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -