이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e6 + 2;
vector<int> pos[N];
int n, m, a[N], b[N];
bool vis[N];
long long dp[20][(1LL << 20) + 1];
long long gen(int i, long long sum, vector<int>& cur){
if(i == m){
long long power = 0;
for(auto k : cur)
power = (power | k);
pos[sum].push_back(power);
return 0;
}
vector<int> cur1 = cur;
gen(i + 1, sum, cur1);
cur1.push_back(i);
gen(i + 1, sum + b[i], cur1);
}
bool go(int i, long long mask){
if(i == n)
return true;
if(dp[i][mask] != -1)
return dp[i][mask];
bool ans = false;
for(auto k : pos[a[i]]){
if(mask & k != 0) continue;
ans |= go(i + 1, mask | k);
}
return dp[i][mask] = ans;
}
void solve() {
memset(dp, -1, sizeof dp);
cin >> n >> m;
for(int i = 0; i < n; ++i)
cin >> a[i];
for(int i = 0; i < m; ++i)
cin >> b[i];
vector<int> ok;
gen(0, 0, ok);
cout << (go(0, 0) ? "YES\n" : "NO\n");
}
int main() {
fast;
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool go(int, long long int)':
bank.cpp:32:15: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
32 | if(mask & k != 0) continue;
| ~~^~~~
bank.cpp:35:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
35 | return dp[i][mask] = ans;
| ~~~~~~~~~~~~^~~~~
bank.cpp: In function 'long long int gen(int, long long int, std::vector<int>&)':
bank.cpp:19:24: warning: control reaches end of non-void function [-Wreturn-type]
19 | vector<int> cur1 = cur;
| ^~~
# | 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... |