| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1308616 | AgentPengin | 은행 (IZhO14_bank) | C++20 | 2 ms | 832 KiB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define vt vector
#define unmap unordered_map
#define unset unordered_set
#define pri priority_queue
#define ub upper_bound
#define lb lower_bound
#define ll long long
// #define int long long
#define getbit(x,i) ((x >> i) & 1ll)
#define NAME "chick"
using namespace std;
const ll inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 21;
int n,m,a[maxn],b[maxn],dp[maxn][1<<maxn];
vt<int> d[maxn];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(NAME".inp","r")){
freopen(NAME".inp","r",stdin);
freopen(NAME".out","w",stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= m; i++){
cin >> b[i];
}
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);//
for(int mask = 0; mask < (1 << m); mask++){
int sum = 0;
for(int j = 1; j <= m; j++){
if(getbit(mask,j-1)) sum += b[j];
}
for(int i = 1; i <= n; i++){
if(a[i] == sum) d[i].pb(mask);
}
}
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
for(int mask = 0; mask < (1 << m); mask++){
for(auto x : d[i]){
if(mask & x != x) continue;
dp[i][mask] |= dp[i-1][~(mask ^ x)];
}
if(i == n && dp[i][mask]){
cout << "YES";
return 0;
}
}
}
cout << "NO";
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
