Submission #39089

# Submission time Handle Problem Language Result Execution time Memory
39089 2018-01-09T09:40:53 Z mrtsima22 Bank (IZhO14_bank) C++14
52 / 100
140 ms 8552 KB
#include <bits/stdc++.h>
using namespace std;
int b[1000003],n,m,s[1000003],sum[1000003];
int g[1000003],d[23][1000003],jam[1000003];
string ans="NO";
int main(){std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<n;i++)
{
	cin>>b[i];
	sum[i]=sum[i-1]+b[i];
}
for(int i=0;i<m;i++)
{
	cin>>g[i];
}
for(int i=0;i<(1<<m);i++)
{
	for(int j=0;j<m;j++)
	{
		if(!((i>>j)&1))
		{
			jam[i|(1<<j)]=jam[i]+g[j];
		}
	}
}
d[0][0]=1;
for(int i=0;i<=n;i++)
{
	for(int j=0;j<(1<<m);j++)
	{
		if(!d[i][j])
		{
			continue;
		}
		if(i==n)
		{
			ans="YES";
			break;
		}
		if(sum[i]==jam[j])
		{
			d[i+1][j]=1;
		}
		for(int t=0; t<m; t++)
		{
			if(!((j>>t)&1))
			{
				d[i][j|(1<<t)]=1;		
			}
		}
	}
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/


# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 6 ms 824 KB Output is correct
5 Incorrect 140 ms 8552 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8552 KB Output is correct
2 Correct 2 ms 8552 KB Output is correct
3 Correct 2 ms 8552 KB Output is correct
4 Correct 2 ms 8552 KB Output is correct
5 Correct 2 ms 8552 KB Output is correct
6 Correct 2 ms 8552 KB Output is correct
7 Correct 2 ms 8552 KB Output is correct
8 Correct 2 ms 8552 KB Output is correct
9 Correct 2 ms 8552 KB Output is correct
10 Correct 2 ms 8552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8552 KB Output is correct
2 Correct 4 ms 8552 KB Output is correct
3 Correct 5 ms 8552 KB Output is correct
4 Correct 4 ms 8552 KB Output is correct
5 Correct 4 ms 8552 KB Output is correct
6 Correct 4 ms 8552 KB Output is correct
7 Correct 4 ms 8552 KB Output is correct
8 Correct 4 ms 8552 KB Output is correct
9 Correct 4 ms 8552 KB Output is correct
10 Correct 4 ms 8552 KB Output is correct
11 Correct 4 ms 8552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 6 ms 824 KB Output is correct
5 Incorrect 140 ms 8552 KB Output isn't correct
6 Halted 0 ms 0 KB -