# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68487 | MrTEK | Bank (IZhO14_bank) | C++14 | 431 ms | 22888 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 mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define cout maltahsin
#define left ind + ind
#define right ind + ind + 1
#define mid (l + r) / 2
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define FAST_IO ios_base::sync_with_stdio(false);
#define endl '\n'
const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9 + 5;
const int N = 20;
const int M = (2 << 20) + 5;
const int K = 1e3 + 5;
const int SQ = 350;
const int MOD = 998244353;
typedef pair <int,int> pii;
vector <int> S[K];
int n,m,dp[2][M],a[N],b[N];
void brute(int cur,int sum,int mask) {
if (cur == m) {
if (sum <= 1e3) S[sum].push_back(mask);
return;
}
brute(cur + 1,sum,mask);
brute(cur + 1,sum + b[cur],mask + (1 << cur));
}
int main() {
scanf("%d %d",&n,&m);
for (int i = 0 ; i < n ; i++) scanf("%d",&a[i]);
for (int i = 0 ; i < m ; i++) scanf("%d",&b[i]);
brute(0,0,0);
dp[0][0] = 1;
int cur = 0, nxt = 1;
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < M ; j++) {
if (!dp[cur][j]) continue;
for (auto it : S[a[i]]) {
if ((j & it) == 0) {
dp[nxt][j + it] |= dp[cur][j];
}
}
}
for (int j = 0 ; j < M ; j++) dp[cur][j] = 0;
swap(cur,nxt);
}
int ans = 0;
for (int i = 0 ; i < M ; i++) ans |= dp[cur][i];
printf(ans ? "YES\n" : "NO\n");
}
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... |