# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
115722 |
2019-06-08T19:02:57 Z |
mrboorger |
Bank (IZhO14_bank) |
C++14 |
|
578 ms |
24020 KB |
#include <bits/stdc++.h>
#pragma optimize ("-Ofast")
//#pragma comment (linker, "-STACK 99999999")
#define ld long double
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
//#define int long long
using namespace std;
const int maxn = 22;
int inf = 1e9 + 15;
int a[maxn], b[maxn];
bool dp[maxn][1 << maxn];
//mask, count of pays
int32_t main()
{
#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
for(int i = 0; i < m; i++)
{
cin >> b[i];
}
if (n > m)
{
cout << "NO";
return 0;
}
vector <pair <int, int>> vc;
for(int i = 0; i < (1 << m); i++)
{
int val = 0;
for(int j = 0; j < m; j++)
{
if ((i & (1 << j)) > 0)
{
val += b[j];
}
}
vc.pb({val, i});
}
sort(vc.begin(), vc.end());
dp[0][0] = true;
for(int i = 0; i < n; i++)
for(int mask = 0; mask < (1 << m); mask++)
{
if (!dp[i][mask])
{
continue;
}
auto it = lower_bound(vc.begin(), vc.end(), make_pair(a[i], 0));
for(it; it != vc.end() && (*it).F == a[i]; it++)
{
if (((*it).S & mask) == 0)
{
dp[i + 1][(*it).S | mask] = true;
}
}
}
bool f = false;
for(int mask = 0; mask < (1 << m); mask++)
{
if (dp[n][mask])
{
f = true;
break;
}
}
if (f)
{
cout << "YES";
}
else
{
cout << "NO";
}
return 0;
}
Compilation message
bank.cpp:3:0: warning: ignoring #pragma optimize [-Wunknown-pragmas]
#pragma optimize ("-Ofast")
bank.cpp: In function 'int32_t main()':
bank.cpp:72:15: warning: statement has no effect [-Wunused-value]
for(it; it != vc.end() && (*it).F == a[i]; it++)
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
768 KB |
Output is correct |
5 |
Correct |
190 ms |
8788 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
192 ms |
9756 KB |
Output is correct |
9 |
Correct |
194 ms |
8788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
768 KB |
Output is correct |
5 |
Correct |
190 ms |
8788 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
192 ms |
9756 KB |
Output is correct |
9 |
Correct |
194 ms |
8788 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
640 KB |
Output is correct |
21 |
Correct |
4 ms |
640 KB |
Output is correct |
22 |
Correct |
4 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
640 KB |
Output is correct |
24 |
Correct |
4 ms |
640 KB |
Output is correct |
25 |
Correct |
4 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
640 KB |
Output is correct |
27 |
Correct |
4 ms |
640 KB |
Output is correct |
28 |
Correct |
5 ms |
640 KB |
Output is correct |
29 |
Correct |
4 ms |
640 KB |
Output is correct |
30 |
Correct |
4 ms |
640 KB |
Output is correct |
31 |
Correct |
193 ms |
9536 KB |
Output is correct |
32 |
Correct |
265 ms |
10820 KB |
Output is correct |
33 |
Correct |
199 ms |
10068 KB |
Output is correct |
34 |
Correct |
210 ms |
8916 KB |
Output is correct |
35 |
Correct |
200 ms |
8916 KB |
Output is correct |
36 |
Correct |
213 ms |
8912 KB |
Output is correct |
37 |
Correct |
195 ms |
8788 KB |
Output is correct |
38 |
Correct |
195 ms |
8788 KB |
Output is correct |
39 |
Correct |
199 ms |
13908 KB |
Output is correct |
40 |
Correct |
240 ms |
8772 KB |
Output is correct |
41 |
Correct |
211 ms |
8916 KB |
Output is correct |
42 |
Correct |
209 ms |
12204 KB |
Output is correct |
43 |
Correct |
201 ms |
9428 KB |
Output is correct |
44 |
Correct |
201 ms |
8784 KB |
Output is correct |
45 |
Correct |
194 ms |
11220 KB |
Output is correct |
46 |
Correct |
198 ms |
10832 KB |
Output is correct |
47 |
Correct |
202 ms |
9052 KB |
Output is correct |
48 |
Correct |
228 ms |
9656 KB |
Output is correct |
49 |
Correct |
195 ms |
8680 KB |
Output is correct |
50 |
Correct |
303 ms |
24020 KB |
Output is correct |
51 |
Correct |
178 ms |
8920 KB |
Output is correct |
52 |
Correct |
193 ms |
11856 KB |
Output is correct |
53 |
Correct |
578 ms |
16596 KB |
Output is correct |
54 |
Correct |
330 ms |
23636 KB |
Output is correct |
55 |
Correct |
309 ms |
23992 KB |
Output is correct |
56 |
Correct |
325 ms |
24020 KB |
Output is correct |
57 |
Correct |
321 ms |
23040 KB |
Output is correct |
58 |
Correct |
329 ms |
22996 KB |
Output is correct |