이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Arayi
#include <bits/stdc++.h>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;
lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = {'a', 'e', 'i', 'o', 'u'};
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1, 0};
int dy[] = {-1, 0, 1, 0, -1, 1, -1, 1, 0};
char dc[] = {'R', 'D', 'L', 'U'};
const int N = 3e6 + 20;
const lli mod = LLONG_MAX;
const ld pi = acos(-1);
const ld e = 1e-13;
const int T = 200;
lli bp(lli a, lli b = mod - 2LL)
{
lli ret = 1;
while (b)
{
if (b & 1)
ret *= a, ret %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ret;
}
ostream &operator<<(ostream &c, pir a)
{
c << a.fr << " " << a.sc;
return c;
}
template <class T>
void maxi(T &a, T b)
{
a = max(a, b);
}
template <class T>
void mini(T &a, T b)
{
a = min(a, b);
}
int n, m;
int a[N], b[N];
vii fp[N];
bool dp[21][N];
vii s[N];
int main()
{
fastio;
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 x = 0; x < (1 << m); x++)
{
int sum = 0;
for (int i = 0; i < m; i++)
if ((1 << i) & x)
sum += b[i];
fp[sum].ad(x);
}
dp[0][0] = 1;
int sum = 0;
for (int i = 0; i < n; i++)
{
sum += a[i];
for (int j = 0; j < (1 << m); j++)
s[j].clear();
for(auto p : fp[a[i]])
s[p].ad(p);
for (int j = 0; j < m; j++)
{
for (int x = (1 << m) - 1; x >= 0; x--)
{
if (((1 << j) & x))
continue;
for (auto p : s[x])
s[x ^ (1 << j)].ad(p);
}
}
for (auto p : fp[sum])
{
for (auto p1 : s[p])
{
if (dp[i][p ^ p1])
{
dp[i + 1][p] = 1;
break;
}
}
}
}
bool pat = 0;
for (auto p : fp[sum])
if (dp[n][p])
pat = 1;
if (pat)
cout << "YES" << endl;
else
cout << "NO" << 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... |