#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define REP(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define mp make_pair
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define Bit(x, i) ((x >> (i)) & 1)
#define Mask(i) (1 << (i))
#define Cnt(x) __builtin_popcount(x)
#define Cntll(x) __builtin_popcountll(x)
#define Clz(x) __builtin_clz(x) // first bit
#define Clzll(x) __builtin_clzll(x)
inline bool maximize(int &u, int v){
return v > u ? u = v, true : false;
}
inline bool minimize(int &u, int v){
return v < u ? u = v, true : false;
}
inline bool maximizell(long long &u, long long v){
return v > u ? u = v, true : false;
}
inline bool minimizell(long long &u, long long v){
return v < u ? u = v, true : false;
}
const int mod = 1e9 + 7;
inline int fastPow(int a, int n){
if(n == 0) return 1;
int t = fastPow(a, n >> 1);
t = 1ll * t * t % mod;
if(n & 1) t = 1ll * t * a % mod;
return t;
}
inline void add(int &u, int v){
u += v;
if(u >= mod) u -= mod;
}
inline void sub(int &u, int v){
u -= v;
if(u < 0) u += mod;
}
const int maxN = 2e5 + 5;
const int inf = 1e9;
const long long infll = 1e18;
int n, m, a[20], b[20];
int s[1 << 20];
vector<int> query[20001];
bool f[20][1 << 20];
void process(){
cin >> n >> m;
FOR(i, 0, n - 1)cin >> a[i];
FOR(i, 0, m - 1)cin >> b[i], s[1 << i] = b[i];
if(n > m) {
cout << "NO\n";
return;
}
int maxMask = Mask(m) - 1;
FOR(mask, 1, maxMask){
if(Cnt(mask) >= 2){
int tmp = mask & -mask;
s[mask] = s[mask ^ tmp] + s[tmp];
}
query[s[mask]].emplace_back(mask);
}
for(int mask : query[a[0]]) f[0][mask] = true;
int pref = 0;
for(int i = 0; i < n - 1; ++i){
pref += a[i];
for(int mask : query[pref]){
if(f[i][mask]){
for(int nxtMask : query[a[i + 1]]){
if((mask ^ nxtMask) == 0)f[i + 1][nxtMask] = true;
}
}
}
}
FOR(mask, 1, maxMask) if(f[n - 1][mask]){
cout << "YES\n";
return;
}
cout << "NO\n";
}
#define LOVE "bank"
int main(){
if(fopen(LOVE".in", "r")){
freopen(LOVE".in", "r", stdin);
freopen(LOVE".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--)
process();
// cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'int main()':
bank.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen(LOVE".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(LOVE".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |