제출 #795505

#제출 시각아이디문제언어결과실행 시간메모리
795505serifefedartar은행 (IZhO14_bank)C++17
100 / 100
402 ms7136 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; typedef pair<int,int> pii; typedef pair<int,ll> pil; #define f first #define s second #define MOD 998244353 #define LOGN 20 #define MAXN 1005 vector<bool> dp(1<<21, 0); int main() { fast int N, M; cin >> N >> M; vector<int> A(N), B(M); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < M; i++) cin >> B[i]; int mx_mask = (1<<M)-1; vector<vector<int>> sums(1005, vector<int>()); for (int mask = 0; mask <= mx_mask; mask++) { int sum = 0; for (int i = 0; i < M; i++) { if ((1<<i) & mask) sum += B[i]; } if (sum <= 1000) sums[sum].push_back(mask); } dp[0] = 1; for (int person = 0; person < N; person++) { vector<bool> new_dp(1<<21, 0); for (int mask = 0; mask <= mx_mask; mask++) { if (!dp[mask]) continue; for (auto u : sums[A[person]]) { if ((mask & u) == 0) new_dp[mask | u] = 1; } } dp = new_dp; } for (auto u : dp) { if (u) { cout << "YES\n"; return 0; } } cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...