# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
171931 |
2019-12-30T16:23:44 Z |
davitmarg |
Bank (IZhO14_bank) |
C++17 |
|
1000 ms |
64380 KB |
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 25;
int n, m, dp[N][(1 << 20) + 5];
int a[N], b[N], sum[(1 << 20) + 5];
vector<int> masks[N * 1003];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> b[i];
for (int mask = 0; mask < (1 << m); mask++)
{
for (int i = 0; i < m; i++)
if (((1 << i) & mask))
sum[mask] += b[i + 1];
masks[sum[mask]].PB(mask);
//cout << mask << " = " << sum[mask] << endl;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < masks[a[i]].size(); j++)
{
int mask = masks[a[i]][j];
int s = (1 << m) - 1 - mask;
while (s >= 0)
{
if (dp[i - 1][s])
dp[i][mask | s] = 1;
if (s == 0)
break;
s = (s - 1) & ((1 << m) - 1 - mask);
}
}
//for (int mask = 0; mask < (1 << m); mask++)
// cout << i << " : " << mask << " = " << dp[i][mask] << endl;
}
int ans = 0;
for (int mask = 0; mask < (1 << m); mask++)
ans += dp[n][mask];
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
/*
2 4
9 10
5 4 5 5
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
*/
Compilation message
bank.cpp: In function 'int main()':
bank.cpp:51:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < masks[a[i]].size(); j++)
~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
888 KB |
Output is correct |
4 |
Correct |
6 ms |
1404 KB |
Output is correct |
5 |
Correct |
104 ms |
11640 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
888 KB |
Output is correct |
8 |
Correct |
116 ms |
14556 KB |
Output is correct |
9 |
Correct |
102 ms |
10872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1020 KB |
Output is correct |
2 |
Correct |
3 ms |
1016 KB |
Output is correct |
3 |
Correct |
3 ms |
1020 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
3 ms |
1016 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
888 KB |
Output is correct |
8 |
Correct |
3 ms |
1016 KB |
Output is correct |
9 |
Correct |
3 ms |
956 KB |
Output is correct |
10 |
Correct |
3 ms |
996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
5 ms |
1272 KB |
Output is correct |
3 |
Correct |
5 ms |
1272 KB |
Output is correct |
4 |
Correct |
5 ms |
1144 KB |
Output is correct |
5 |
Correct |
5 ms |
1144 KB |
Output is correct |
6 |
Correct |
4 ms |
1144 KB |
Output is correct |
7 |
Correct |
4 ms |
1144 KB |
Output is correct |
8 |
Correct |
5 ms |
1272 KB |
Output is correct |
9 |
Correct |
5 ms |
1144 KB |
Output is correct |
10 |
Correct |
5 ms |
1144 KB |
Output is correct |
11 |
Correct |
4 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
888 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
888 KB |
Output is correct |
4 |
Correct |
6 ms |
1404 KB |
Output is correct |
5 |
Correct |
104 ms |
11640 KB |
Output is correct |
6 |
Correct |
3 ms |
1016 KB |
Output is correct |
7 |
Correct |
3 ms |
888 KB |
Output is correct |
8 |
Correct |
116 ms |
14556 KB |
Output is correct |
9 |
Correct |
102 ms |
10872 KB |
Output is correct |
10 |
Correct |
3 ms |
1020 KB |
Output is correct |
11 |
Correct |
3 ms |
1016 KB |
Output is correct |
12 |
Correct |
3 ms |
1020 KB |
Output is correct |
13 |
Correct |
3 ms |
1016 KB |
Output is correct |
14 |
Correct |
3 ms |
1016 KB |
Output is correct |
15 |
Correct |
3 ms |
1016 KB |
Output is correct |
16 |
Correct |
3 ms |
888 KB |
Output is correct |
17 |
Correct |
3 ms |
1016 KB |
Output is correct |
18 |
Correct |
3 ms |
956 KB |
Output is correct |
19 |
Correct |
3 ms |
996 KB |
Output is correct |
20 |
Correct |
5 ms |
1144 KB |
Output is correct |
21 |
Correct |
5 ms |
1272 KB |
Output is correct |
22 |
Correct |
5 ms |
1272 KB |
Output is correct |
23 |
Correct |
5 ms |
1144 KB |
Output is correct |
24 |
Correct |
5 ms |
1144 KB |
Output is correct |
25 |
Correct |
4 ms |
1144 KB |
Output is correct |
26 |
Correct |
4 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
1272 KB |
Output is correct |
28 |
Correct |
5 ms |
1144 KB |
Output is correct |
29 |
Correct |
5 ms |
1144 KB |
Output is correct |
30 |
Correct |
4 ms |
1144 KB |
Output is correct |
31 |
Correct |
119 ms |
13752 KB |
Output is correct |
32 |
Correct |
228 ms |
18552 KB |
Output is correct |
33 |
Correct |
132 ms |
12408 KB |
Output is correct |
34 |
Correct |
130 ms |
11512 KB |
Output is correct |
35 |
Correct |
136 ms |
12272 KB |
Output is correct |
36 |
Correct |
164 ms |
11896 KB |
Output is correct |
37 |
Correct |
117 ms |
12152 KB |
Output is correct |
38 |
Correct |
114 ms |
11772 KB |
Output is correct |
39 |
Correct |
229 ms |
26416 KB |
Output is correct |
40 |
Correct |
119 ms |
11960 KB |
Output is correct |
41 |
Correct |
124 ms |
11128 KB |
Output is correct |
42 |
Correct |
180 ms |
20088 KB |
Output is correct |
43 |
Correct |
131 ms |
12792 KB |
Output is correct |
44 |
Correct |
138 ms |
12116 KB |
Output is correct |
45 |
Correct |
139 ms |
19456 KB |
Output is correct |
46 |
Correct |
138 ms |
15592 KB |
Output is correct |
47 |
Correct |
136 ms |
11480 KB |
Output is correct |
48 |
Correct |
130 ms |
14120 KB |
Output is correct |
49 |
Correct |
102 ms |
10832 KB |
Output is correct |
50 |
Correct |
509 ms |
64380 KB |
Output is correct |
51 |
Correct |
282 ms |
11064 KB |
Output is correct |
52 |
Correct |
510 ms |
16172 KB |
Output is correct |
53 |
Execution timed out |
1074 ms |
37964 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |