Submission #703921

# Submission time Handle Problem Language Result Execution time Memory
703921 2023-03-01T00:14:24 Z Hyojin Bank (IZhO14_bank) C++17
100 / 100
104 ms 8532 KB
#include <bits/stdc++.h>
using namespace std;
#define bit(n,i) ((n>>i)&1)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define ep emplace_back
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
#define ll long long
const int MOD=1e9+7;
const int base=31;
const int N=1e6+5;
int n,m,leftover[1<<20],num_people[1<<20],bank[20],salary[20];
int main()
{
	#ifdef Hyojin
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif //Hyojin
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for (int i=0;i<n;i++) cin>>salary[i];
	for (int i=0;i<m;i++) cin>>bank[i];
	memset(num_people,-1,sizeof num_people);
	memset(leftover,-1,sizeof leftover);
	leftover[0]=num_people[0]=0;
	for (int mask=0;mask<(1<<m);mask++)
	{
		for (int i=0;i<m;i++)
		{
			if (bit(mask,i))
			{
				int premask=mask-(1<<i);
				if (num_people[premask]==-1) continue;
				int total=leftover[premask]+bank[i];
				int cur=salary[num_people[premask]];
				if (total<cur)
				{
					leftover[mask]=total;
					num_people[mask]=num_people[premask];
				}
				if (total==cur)
				{
					leftover[mask]=0;
					num_people[mask]=num_people[premask]+1;
				}
			}
		}
		if (num_people[mask]==n)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8480 KB Output is correct
2 Correct 5 ms 8532 KB Output is correct
3 Correct 4 ms 8440 KB Output is correct
4 Correct 4 ms 8520 KB Output is correct
5 Correct 60 ms 8504 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 4 ms 8404 KB Output is correct
9 Correct 69 ms 8496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 4 ms 8532 KB Output is correct
3 Correct 4 ms 8404 KB Output is correct
4 Correct 4 ms 8404 KB Output is correct
5 Correct 4 ms 8520 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 4 ms 8532 KB Output is correct
8 Correct 4 ms 8516 KB Output is correct
9 Correct 4 ms 8404 KB Output is correct
10 Correct 4 ms 8520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8520 KB Output is correct
2 Correct 4 ms 8404 KB Output is correct
3 Correct 5 ms 8520 KB Output is correct
4 Correct 4 ms 8532 KB Output is correct
5 Correct 4 ms 8404 KB Output is correct
6 Correct 4 ms 8404 KB Output is correct
7 Correct 5 ms 8404 KB Output is correct
8 Correct 4 ms 8404 KB Output is correct
9 Correct 4 ms 8404 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 4 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8480 KB Output is correct
2 Correct 5 ms 8532 KB Output is correct
3 Correct 4 ms 8440 KB Output is correct
4 Correct 4 ms 8520 KB Output is correct
5 Correct 60 ms 8504 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 4 ms 8404 KB Output is correct
8 Correct 4 ms 8404 KB Output is correct
9 Correct 69 ms 8496 KB Output is correct
10 Correct 4 ms 8404 KB Output is correct
11 Correct 4 ms 8532 KB Output is correct
12 Correct 4 ms 8404 KB Output is correct
13 Correct 4 ms 8404 KB Output is correct
14 Correct 4 ms 8520 KB Output is correct
15 Correct 4 ms 8404 KB Output is correct
16 Correct 4 ms 8532 KB Output is correct
17 Correct 4 ms 8516 KB Output is correct
18 Correct 4 ms 8404 KB Output is correct
19 Correct 4 ms 8520 KB Output is correct
20 Correct 4 ms 8520 KB Output is correct
21 Correct 4 ms 8404 KB Output is correct
22 Correct 5 ms 8520 KB Output is correct
23 Correct 4 ms 8532 KB Output is correct
24 Correct 4 ms 8404 KB Output is correct
25 Correct 4 ms 8404 KB Output is correct
26 Correct 5 ms 8404 KB Output is correct
27 Correct 4 ms 8404 KB Output is correct
28 Correct 4 ms 8404 KB Output is correct
29 Correct 4 ms 8404 KB Output is correct
30 Correct 4 ms 8404 KB Output is correct
31 Correct 81 ms 8404 KB Output is correct
32 Correct 85 ms 8508 KB Output is correct
33 Correct 69 ms 8404 KB Output is correct
34 Correct 57 ms 8524 KB Output is correct
35 Correct 58 ms 8508 KB Output is correct
36 Correct 58 ms 8516 KB Output is correct
37 Correct 57 ms 8516 KB Output is correct
38 Correct 57 ms 8504 KB Output is correct
39 Correct 3 ms 8516 KB Output is correct
40 Correct 57 ms 8404 KB Output is correct
41 Correct 57 ms 8404 KB Output is correct
42 Correct 104 ms 8512 KB Output is correct
43 Correct 67 ms 8520 KB Output is correct
44 Correct 57 ms 8508 KB Output is correct
45 Correct 4 ms 8520 KB Output is correct
46 Correct 83 ms 8532 KB Output is correct
47 Correct 57 ms 8404 KB Output is correct
48 Correct 4 ms 8520 KB Output is correct
49 Correct 56 ms 8404 KB Output is correct
50 Correct 83 ms 8520 KB Output is correct
51 Correct 58 ms 8520 KB Output is correct
52 Correct 63 ms 8508 KB Output is correct
53 Correct 90 ms 8504 KB Output is correct
54 Correct 95 ms 8508 KB Output is correct
55 Correct 81 ms 8404 KB Output is correct
56 Correct 78 ms 8404 KB Output is correct
57 Correct 78 ms 8508 KB Output is correct
58 Correct 80 ms 8404 KB Output is correct