제출 #881661

#제출 시각아이디문제언어결과실행 시간메모리
881661yifei04은행 (IZhO14_bank)C++17
0 / 100
1026 ms2396 KiB
#include <iostream> #include <vector> #include <array> #include <algorithm> #include <cmath> #include <bitset> using namespace std; #define ll long long #define all(x) x.begin(), x.end() constexpr int MAXN = 1 << 21; void solve() { int n, m; cin >> n >> m; vector<int> a(n + 1); for (int i = 1; i <= n; ++i) { cin >> a[i]; } vector<int> b(m); for (int &x : b) { cin >> x; } // suppongo di aggiustare una persona alla volta int mx = 1 << m; vector<bitset<MAXN>> dp(n + 1); dp[0][0] = true; vector<vector<int>> good_mask(n + 1); // per ogni persona vedo che mask va bene for (int i = 1; i <= n; ++i) { // itero su tutte le submask for (int mask = 0; mask < mx; ++mask) { int sum = 0; for (int j = 0; j < mx; ++j) { if (mask & (1 << j)) { sum += b[i]; } } if (sum == a[i]) { good_mask[i].push_back(mask); } } } for (int i = 0; i < n; ++i) { for (int mask = 0; mask < mx; ++mask) { if (!dp[i][mask]) { continue; } int cur = __builtin_popcount(mask); for (int new_mask : good_mask[i + 1]) { int cur_add = __builtin_popcount(new_mask); int msk = mask | new_mask; if (__builtin_popcount(msk) == cur + cur_add) { // e' un set indipendente dp[i + 1][msk] = true; } } } } for (int mask = 0; mask < mx; ++mask) { if (dp[n][mask]) { cout << "YES"; return; } } cout << "NO"; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt = 1; // cin >> tt; while (tt--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...