# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1175366 | Hisu | 은행 (IZhO14_bank) | C++20 | 970 ms | 70456 KiB |
// Chaiyo...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ed "\n"
//#define int long long
const int N = 2e6 + 5;
int n, m, a[N], b[N];
vector<int> st[N];
struct chash {
const uint64_t C = ll(4e18*acos(0))+71; // large odd number
const int RANDOM = rand();
ll operator()(ll x) const { return __builtin_bswap64((x^RANDOM)*C); }
};
template<class K,class V> using ht = gp_hash_table<K,V,chash>;
template<class K,class V> V get(ht<K,V>& u, K x) {
auto it = u.find(x); return it == end(u) ? 0 : it->s; }
void solve(int iTest){
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 mask = 1; mask < (1 << m); mask++) {
int sum = 0;
for(int i = 0; i < m; i++) if(mask >> i & 1) sum += b[i + 1];
st[sum].push_back(mask);
}
gp_hash_table<int, bool> dp;
dp[0] = true;
for(int i = 1; i <= n; i++) {
gp_hash_table<int, bool> new_dp;
for(int val : st[a[i]]) {
for(auto [mask, x] : dp) if((mask & val) == 0)
new_dp[mask ^ val] = true;
}
dp.swap(new_dp);
if(dp.size() == 0) break;
}
if(dp.size()) cout << "YES";
else cout << "NO";
}
#define TASK "main"
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
if(fopen(TASK ".inp","r")){
freopen(TASK ".inp","r",stdin);
freopen(TASK ".out","w",stdout);
}
else if(fopen("main.inp","r")){
freopen("main.inp","r",stdin);
freopen("main.out","w",stdout);
}
int T = 1;
// cin >> T;
for(int iTest = 1; iTest <= T; iTest++){
solve(iTest);
}
}
/**
**/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |