# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892341 | AgentPengin | Bank (IZhO14_bank) | C++14 | 360 ms | 20952 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.
/**
* author: AgentPengin ( Độc cô cầu bại )
* created: 23.12.2022 10:08:02
* too lazy to update time
**/
#include<bits/stdc++.h>
#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 25;
int n,m,a[25],b[25];
bool dp[21][(1 << 20) + 1];
// dp[i][mask] -> trả tiền cho i-th người với mask = ?
// dp[i + 1][mask] = fo
vector<int> adj[21];
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if (ifstream(NAME".inp")) {
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];
for (int mask = 1;mask < (1 << m);mask++) {
int money = 0;
for (int i = 0;i < m;i++) {
if (mask >> i & 1) money += b[i + 1];
}
for (int i = 0;i < n;i++) {
if (money == a[i + 1]) adj[i + 1].push_back(mask);
}
}
dp[0][0] = true;
for (int i = 0;i < n;i++) {
for (int mask = 0;mask < (1 << m);mask++) {
if (!dp[i][mask]) continue;
for (auto x : adj[i + 1]) {
if ((mask & x) == 0) {
dp[i + 1][mask ^ x] = true;
}
}
}
}
for (int mask = 1;mask < (1 << m);mask++) {
if (dp[n][mask] == true) return cout << "YES",0;
}
cout << "NO";
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
// agent pengin wants to take apio (with anya-san)
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... |