| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 171007 | beksultan04 | Bank (IZhO14_bank) | C++14 | 642 ms | 30832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define OK puts("OK");
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define rep(i,n) for (i=0;i<(n);++i)
#define rep1(i,n) for (i=1;i<=(n);++i)
#define ret return
#define nemeshay ios::sync_with_stdio(0),cin.tie(0);
const int N=30,INF=1e9+7;
int a[N],b[N],n,m;
bool vis[25][(1<<21)];
bool dp[25][(1<<21)];
int sum[(1<<21)];
vector<int> v[21];
bool possible(int s,int j){
if (j==n)ret 1;
if (vis[j][s])ret dp[j][s];
vis[j][s]=1;
bool flag=0;
for (int i=0;i<v[j].size();++i)
if (!(s&v[j][i]))flag |= possible(s|v[j][i],j+1);
ret dp[j][s]=flag;
}
int sum_bin(int a){
int i,c=0;
for (i=0;i<m;++i)
if ((a&(1<<i)))
c+=b[i];
ret c;
}
main(){
int i,c=1,j;
cin>>n>>m;
rep(i,n)scanf("%d",&a[i]);
rep(i,m)scanf("%d",&b[i]);
for (i=1;i<(1<<m);++i){
int x=sum_bin(i);
for (j=0;j<n;++j)
if (x==a[j])
v[j].pb(i);
}
if (possible(0,0))
cout <<"YES";
else cout <<"NO";
}
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... | ||||
