# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
171390 |
2019-12-28T14:15:44 Z |
Swan |
은행 (IZhO14_bank) |
C++14 |
|
540 ms |
2668 KB |
#include <bits/stdc++.h>
#define stop system("pause")
#define stop2 char o; cin >> o
#define INP freopen("pcb.in","r",stdin)
#define OUTP freopen ("pcb.out","w",stdout)
//#define int long long
using namespace std;
const int maxn = 20;
vector<int> a,b;
vector<int> masks[22];
map<int,vector<int> > qwe;
bitset<(1<<20)> dp[20];
main(){
ios_base::sync_with_stdio(0);
int n,m;
cin >> n >> m;
for(int i(0); i < n;i++){
int x; cin >> x;
b.push_back(x);
qwe[x].push_back(i);
}
for(int i(0); i < m;i++){
int x; cin >> x;
a.push_back(x);
}
for(int i(0); i < (1<<m);i++){
int sum = 0;
for(int j(0); j < m;j++){
int bit = i&(1<<j);
if(!bit)continue;
else sum+=a[j];
}
//cout << sum << endl;
if(!qwe.count(sum))continue;
//cout << sum << endl;
for(int j(0); j < qwe[sum].size();j++){
//cerr << qwe[j][i] << endl;
if(!qwe[sum][j]){
dp[0][i] = 1;
//cout << sum << endl;
}
masks[qwe[sum][j]].push_back(i);
//cout << qwe[j][i] << ' ' << i << endl;
}
}
for(int k(0); k < n-1;k++){
for(int mask(0); mask < (1<<m);mask++){
if(!dp[k][mask])continue;
for(int z(0); z < masks[k+1].size();z++){
int to = masks[k+1][z];
bool f = (mask&to);
if(f)continue;
dp[k+1][to^mask] = 1;
//cout << k+1 << ' ' << mask << ' ' << to << ' ' << (to^mask) << endl;
}
}
}
for(int mask(0); mask < (1<<m);mask++){
if(dp[n-1][mask]){
cout << "YES";
return 0;
}
}
cout << "NO";
return 0;
}
/*
1 5
8
4 2 5 1 3
*/
Compilation message
bank.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
bank.cpp: In function 'int main()':
bank.cpp:40:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j(0); j < qwe[sum].size();j++){
~~^~~~~~~~~~~~~~~~~
bank.cpp:53:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int z(0); z < masks[k+1].size();z++){
~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
89 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
0 ms |
376 KB |
Output is correct |
8 |
Correct |
86 ms |
504 KB |
Output is correct |
9 |
Correct |
88 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
420 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
4 ms |
388 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
89 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
0 ms |
376 KB |
Output is correct |
8 |
Correct |
86 ms |
504 KB |
Output is correct |
9 |
Correct |
88 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
420 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
4 ms |
388 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
4 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
92 ms |
632 KB |
Output is correct |
32 |
Correct |
173 ms |
760 KB |
Output is correct |
33 |
Correct |
102 ms |
836 KB |
Output is correct |
34 |
Correct |
106 ms |
644 KB |
Output is correct |
35 |
Correct |
106 ms |
512 KB |
Output is correct |
36 |
Correct |
120 ms |
524 KB |
Output is correct |
37 |
Correct |
90 ms |
376 KB |
Output is correct |
38 |
Correct |
94 ms |
376 KB |
Output is correct |
39 |
Correct |
113 ms |
1176 KB |
Output is correct |
40 |
Correct |
104 ms |
520 KB |
Output is correct |
41 |
Correct |
120 ms |
504 KB |
Output is correct |
42 |
Correct |
101 ms |
888 KB |
Output is correct |
43 |
Correct |
103 ms |
760 KB |
Output is correct |
44 |
Correct |
111 ms |
508 KB |
Output is correct |
45 |
Correct |
93 ms |
760 KB |
Output is correct |
46 |
Correct |
99 ms |
860 KB |
Output is correct |
47 |
Correct |
113 ms |
504 KB |
Output is correct |
48 |
Correct |
86 ms |
504 KB |
Output is correct |
49 |
Correct |
90 ms |
376 KB |
Output is correct |
50 |
Correct |
215 ms |
2668 KB |
Output is correct |
51 |
Correct |
109 ms |
504 KB |
Output is correct |
52 |
Correct |
109 ms |
1144 KB |
Output is correct |
53 |
Correct |
540 ms |
1528 KB |
Output is correct |
54 |
Correct |
242 ms |
2568 KB |
Output is correct |
55 |
Correct |
215 ms |
2524 KB |
Output is correct |
56 |
Correct |
218 ms |
2488 KB |
Output is correct |
57 |
Correct |
223 ms |
2424 KB |
Output is correct |
58 |
Correct |
223 ms |
2436 KB |
Output is correct |