Submission #660112

#TimeUsernameProblemLanguageResultExecution timeMemory
660112bojackduyBank (IZhO14_bank)C++14
100 / 100
61 ms8504 KiB
#include <iostream> #include <queue> #include <stack> #include <algorithm> #include <string.h> #include <functional> #define task "" #define size() size() * 1ll #define all(x) (x).begin(), (x).end() #define pb push_back #define pii pair<int, int> #define fi first #define se second #define MASK(x) (1LL << (x)) #define BIT(x,i) (((x) >> (i)) & 1) #define numbit(x) __builtin_popcountll(x) using namespace std; typedef vector<int> vi; typedef vector<pii> vii; typedef long long ll; template<class t> bool mini(t &x,t y) { if (y < x) { x = y; return 1; } return 0; } template<class t> bool maxi(t &x,t y) { if (x < y) { x = y; return 1; } return 0; } const int N = 1e6 + 1; const int M = 1e3 + 1; const long long mod = 1e9 + 7; const long long oo = 1e18 + 7; int n, m; int a[20], b[20]; int dp[MASK(20)], lefover[MASK(20)]; void solve(int test = -1) { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; memset(dp, -1, sizeof dp); dp[0] = 0, lefover[0] = 0; for (int mask = 1; mask < MASK(m); mask++) { for (int msk = mask; msk > 0; msk -= msk & -msk) { int i = __builtin_ctz(msk); if (dp[mask ^ MASK(i)] == -1) continue; int sum = lefover[mask ^ MASK(i)] + b[i]; if (sum < a[dp[mask ^ MASK(i)]]) { if (maxi(dp[mask], dp[mask ^ MASK(i)])) lefover[mask] = sum; } else if (sum == a[dp[mask ^ MASK(i)]]) { if (maxi(dp[mask], dp[mask ^ MASK(i)] + 1)) { lefover[mask] = 0; } } if (dp[mask] == n) return void (cout << "YES"); } } cout << "NO"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen(task".inp", "r", stdin); // freopen(task".out", "w", stdout); int T = 1; // cin >> T; for (int i = 1; i <= T; i++) { solve(i); } 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...