이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define po(x) (1<<x)
#define schnell ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL)
#define forn(i,n) for(ll i = 1;i<=n;i++)
typedef long long ll;
typedef long double ld;
#define DIM 25
#define DIM2 DIM*150
#define MODULO 998244353
#define MAXN 1000000
#define MS 302
#define BigNumSize 250
#define AddLimit 151
const ll INF = 10E16;
const ll mask = po(9) - 1;
const ll base = 100000000000;
const ld eps = 0.0000001;
const ll masksz = 1048576;
struct pp {
ll fi, sc;
bool const operator < (const pp& b) {
if (fi == b.fi)return sc < b.sc;
return fi < b.fi;
}
bool const operator > (const pp& b) {
if (fi == b.fi)return sc > b.sc;
return fi > b.fi;
}
bool const operator == (const pp& b) {
if (fi == b.fi && sc == b.sc)return 1;
return 0;
}
};
bool const operator<(const pp& a, const pp& b) {
if (a.fi == b.fi)return a.sc < b.sc;
return a.fi < b.fi;
}
ll n, m, A[DIM], B[DIM], flag = 0;
bool D[DIM][1048579];
vector<ll> G[DIM];
void dfs(ll x, ll mask) {
if (x == n) {
flag = 1;
return;
}
if (D[x][mask])return;
D[x][mask] = 1;
for (ll to : G[x+1]) {
if ((to & mask) == 0)dfs(x + 1, to ^ mask);
}
}
int main() {
schnell;
cin >> n >> m;
forn(i, n)cin >> A[i];
forn(i, m)cin >> B[i];
for (ll i = 0; i < (1 << m); i++) {
ll r=0,mask = i,pos = 1;
while (mask > 0) {
if (mask&1)r += B[pos];
pos++;
mask /= 2;
}
for (ll j = 1; j <= n; j++) {
if (A[j] == r)G[j].pb(i);
}
}
dfs(0,0);
if (flag == 1) {
cout << "YES\n";
}
else {
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... |