이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// In the name of Allah
// Khodaya khodet komak kon
// Hope is last to die
// Let's go
// Hello today I decided to solve at least 4 great problems per day
// 2023/11/24
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define set_dec(x) cout << fixed << setprecision(x);
#define sz(x) ((int)(x).size())
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
const int maxn = 20 + 5, maxB = (1ll << 20);
const int inf = 1e9 + 7;
int a[maxn], b[maxn], sm[maxB];
bool dp[maxn][maxB];
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
for(int mask = 1; mask < (1ll << m); mask++){
int bit = 31 - __builtin_clz(mask);
sm[mask] = sm[mask ^ (1ll << bit)] + b[bit];
}
dp[0][0] = 1;
for(int i = 0; i < n; i++){
for(int mask = 0; mask < (1ll << m); mask++){
if(!dp[i][mask]) continue;
for(int nas = 0; nas < (1ll << m); nas++){
if(nas & mask) continue;
if(sm[nas] == a[i]) dp[i + 1][nas | mask] = 1;
}
}
}
for(int mask = 0; mask < (1ll << m); mask++){
if(dp[n][mask]){
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
return 0;
}
# | 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... |