이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define db long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio\
ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0)\
int a[25], b[25], dp[25][(1 << 20) + 5], n, m;
bool f(int i, int mask){
if(i == n + 1) return true;
if(dp[i][mask] != -1) return dp[i][mask];
vi left;
for(int j = 0; j < m; j++){
if(!((1 << j) & mask)){
left.push_back(j);
}
}
for(int msk = 0; msk < (1 << left.size()); msk++){
int s = 0;
for(int j = 0; j < left.size(); j++){
if((1 << j) & msk){
s += b[left[j] + 1];
}
}
// cout << msk << " " << s << endl;
if(s == a[i]){
int to = mask;
for(int j = 0; j < left.size(); j++){
if((1 << j) & msk){
to |= (1 << left[j]);
}
}
if(f(i + 1, to)){
// cout << i << " " << mask << endl;
return dp[i][mask] = 1;
}
}
}
return dp[i][mask] = 0;
}
signed main(){
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= m; i++){
cin >> b[i];
}
for(int i = 1; i <= n; i++){
for(int mask = 0; mask < (1 << m); mask++){
dp[i][mask] = -1;
}
}
f(1, 0);
for(int mask = 0; mask < (1 << m); mask++){
if(dp[n][mask] == 1){
cout << "YES";
return 0;
}
}
cout << "NO";
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool f(int, int)':
bank.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int j = 0; j < left.size(); j++){
| ~~^~~~~~~~~~~~~
bank.cpp:44:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int j = 0; j < left.size(); j++){
| ~~^~~~~~~~~~~~~
bank.cpp:51:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
51 | return dp[i][mask] = 1;
| ~~~~~~~~~~~~^~~
bank.cpp:55:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
55 | return dp[i][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... |