이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long
#define printarray(arr, n) for(int i= 0;i<n;i++) cout<<arr[i]<<' '; cout<<endl;
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define initdp(a) memset(a, -1, sizeof(a));
#define endl '\n'
#define float long double
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 20;
int fastexpo(int b, int exp){
if(exp == 0) return 1;
if(exp == 1) return b;
int ans = (fastexpo(b,exp/2) % MOD);
ans *= ans;
ans %= MOD;
if(exp % 2 == 1){
ans *= b;
}
ans %= MOD;
return ans;
}
int a[MAXN], b[MAXN];
int n, m;
vector<int> poss[1006];
int dp[MAXN][(1LL<<MAXN)];
bool solve(int idx, int mask){
if(idx == n) return 1;
if(dp[idx][mask] != -1){
if(dp[idx][mask] == 0) return 0;
else return 1;
}
bool ans = 0;
for(auto mask2: poss[a[idx]]){
if(mask2&mask == 0){
ans |= solve(idx+1, mask2||mask);
}
}
if(ans) dp[idx][mask] = 1;
else dp[idx][mask] = 0;
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
initdp(dp);
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 mask = 0;mask<(1LL<<m);mask++){
int sum =0;
for(int i = 0;i<m;i++){
if((1LL<<i) & mask){
sum += b[i];
}
}
poss[sum].pb(mask);
}
if(solve(0, 0)){
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool solve(long long int, long long int)':
bank.cpp:57:17: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
57 | if(mask2&mask == 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... |