제출 #783606

#제출 시각아이디문제언어결과실행 시간메모리
783606acatmeowmeow은행 (IZhO14_bank)C++11
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 20; int n, m, dp[1ll << N], remain[1ll << N], arr[N], note[N]; bool set_bit(int mask, int k) { return mask & (1ll << k); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < m; i++) cin >> note[i]; for (int mask = 0; mask < (1ll << m); mask++) dp[mask] = -1; dp[0] = 0; for (int mask = 0; mask < (1ll << m); mask++) { for (int i = 0; i < m; i++) { if (!set_bit(mask, i)) continue; if (dp[mask] == -1) continue; int pmask = mask ^ (1ll << i), cur = arr[dp[pmask]]; if (remain[pmask] + note[i] < cur) { dp[mask] = dp[pmask]; remain[mask] = remain[pmask] + note[i]; } else if (remain[pmask] + note[i] == cur) { dp[mask] = dp[pmask] + 1; remain[mask] = 0; } } if (dp[mask] == n - 1) { cout << "YES" << '\n'; return 0; } } cout << "NO" << '\n'; 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...