제출 #1053737

#제출 시각아이디문제언어결과실행 시간메모리
1053737sssamui은행 (IZhO14_bank)C++17
100 / 100
75 ms8660 KiB
#include <iostream> #include <cstdio> #include <vector> #include <cmath> using namespace std; const int MXN = 20; int n, m, sz; vector<int> sal(MXN), nts(MXN); bool solve() { vector<int> lft(sz, 0), dp(sz, 0); for (int i = 0; i < n; i++) cin >> sal[i]; for (int i = 0; i < m; i++) cin >> nts[i]; for (int msk = 1; msk < sz; msk++) for (int bit = 0; bit < m; bit++) if (msk & (1 << bit)) if (dp[msk ^ (1 << bit)] >= dp[msk]) { dp[msk] = dp[msk ^ (1 << bit)]; lft[msk] = lft[msk ^ (1 << bit)] + nts[bit]; if (lft[msk] == sal[dp[msk]]) { lft[msk] = 0; dp[msk]++; if (dp[msk] == n) return true; } } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; sz = 1 << m; cout << (solve() ? "YES" : "NO"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...