이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int>PI;
typedef pair<ll, ll > PL;
typedef vector<int>VI;
typedef vector<ll>VL;
#define FF first
#define SS second
const int mod = 1e9 + 7;
const int INF = 1e9;
const int N = 20;
ll dp[22][(1 << N) + 5];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("bank.in", "r", stdin);
//freopen("bank.out", "w", stdout);
int n, m;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < m; i++)
{
cin >> b[i];
}
for (int i = 0; i <= 21; i++)
for (int j = 0; j <= (1 << N); j++) dp[i][j] = -1;
dp[0][0] = 0;
for (int i = 0; i < n; i++)
{
for (int mask = 0; mask < (1 << m); mask++)
{
if (dp[i][mask] == -1) continue;
for (int k = 0; k < m; k++)
if (((mask >> k) & 1) == 0)
dp[i][mask | (1 << k)] = dp[i][mask] + b[k];
}
for (int mask = 0; mask < (1 << m); mask++)
{
if (dp[i][mask] == a[i]) dp[i + 1][mask] = 0;
}
}
bool f1 = 0;
for (int mask = 0; mask < (1 << m); mask++)
if (dp[n][mask] == 0) f1 = 1;
if (f1)
cout << "YES" << endl;
else cout << "NO" << endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
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... |