#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define V vector
#define P pair
#define PI 3.1415926535897932384626
#define mod 1000000007
#define abs(x) (x<0?-(x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define F0(i, a) for (int i = 0; i < (a); i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define readV(v, n) v.resize(n); for (auto &x : v) cin >> x
#define tc int T; cin >> T; while(T--)
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1]
#define REMAX(a,b) (a)=max((a),(b))
#define REMIN(a,b) (a)=min((a),(b))
#define ALL(c) (c).begin(),(c).end()
#define SORT(v) sort(ALL(v))
#define SUM(v) accumulate((v).begin(), (v).end(), 0LL)
#define PRESENT(c,x) ((c).find(x) != (c).end())
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end())
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)
#define FASTIO \
ios ::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const int N = 21;
int n,m,a[N],b[N];
int total(int x){
int ans{0};
F0(i,m){
if(x>>i & 1){
ans += b[i+1];
}
}
return ans;
}
void solve()
{
vector<int> dp(1<<m,0);
vector<int> pre(m,0);
pre[0] = 0;
FE(i,1,n){
pre[i] = pre[i-1] + a[i];
}
F(mask,1,1<<m){
F0(i,m){
if((mask>>i) & 1){
if( total(mask) == pre[dp[mask ^ (1<<i)]+1]){
dp[mask] = max(dp[mask],dp[mask^(1<<i)]+1);
}
else{
dp[mask] = max(dp[mask],dp[mask^(1<<i)]);
}
}
}
if(dp[mask] == n){
cout << "YES";
return;
}
}
cout << "NO";
}
int main(){
FASTIO
cin >> n >> m;
FE(i,1,n) cin >> a[i];
FE(i,1,m) cin >> b[i];
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp:32:26: warning: backslash and newline separated by space
32 | #define FASTIO \
|| # | 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... |