이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//~ using namespace __gnu_pbds;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
//~ #define double long double
//~ #define order_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
///* __ __ __ */
///* ====== _ /| /| __ _ / | | /| | @ | | | | / /| |\ | / | | @ | / */
///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */
///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */
///*
typedef vector<int> vi;
typedef vector<double> vd;
//~ typedef pair<int,int> pii;
//~ typedef vector<pii> vii;
//~ typedef vector<vi> vv;
const int N = 2e5+2, inf = 1e8, mod = 1e9+7;
bitset<1 << 20> dp[2];
vector<int> msks[1001];
void solve() {
cin.tie(0) -> sync_with_stdio(0);
int n, m; cin >> n >> m;
vector<int> a(n), b(m);
for (int& i : a) cin >> i;
for (int& i : b) cin >> i;
for (int i = 0; i < (1 << m); i++) {
int sum = 0;
for (int j = 0; j < m; j++) {
if (i >> j & 1) sum += b[j];
}
if (sum <= 1000) msks[sum].pb(i);
}
for (int i : msks[a[0]]) {
dp[0][i] = true;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (!dp[0][j]) continue;
for (int k : msks[a[i]]) {
if (!(j & k)) dp[1][j | k] = 1;
}
}
dp[0].reset();
swap(dp[0], dp[1]);
}
for (int i = 0; i < (1 << m); i++) {
if (dp[0][i]) {
cout << "YES" << '\n';
return;
}
}
cout << "NO" << '\n';
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int test = 1;
//~ cin >> test;
while(test--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
70 | main(){
| ^~~~
# | 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... |