Submission #1303814

#TimeUsernameProblemLanguageResultExecution timeMemory
1303814peanut은행 (IZhO14_bank)C++20
71 / 100
1096 ms8552 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; template<class X, class Y> bool maximize (X &x, const Y &y) {return x < y ? x = y, 1 : 0;} template<class X, class Y> bool minimize (X &x, const Y &y) {return x > y ? x = y, 1 : 0;} const int maxn = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; int n, m; int salary[20], notes[20]; int sum[1 << 20]; int dp[1 << 20]; int main() { ios::sync_with_stdio(false); cin.tie(0); //freopen(".INP", "r", stdin); //freopen(".OUT", "w", stdout); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> salary[i]; for (int i = 0; i < m; ++i) cin >> notes[i]; for (int i = 0; i < (1 << m); ++i) { for (int j = 0; j < m; ++j) { if (i >> j & 1) sum[i] += notes[j]; } } memset(dp, -1, sizeof dp); dp[0] = 0; for (int i = 0; i < (1 << m); ++i) { if (dp[i] == -1) continue; if (dp[i] == n) { cout << "YES\n"; return 0; } int comp = (~i) & ((1 << m) - 1); for (int j = comp; j; j = (j-1) & comp) { if (sum[j] == salary[dp[i]]) maximize(dp[i | j], dp[i] + 1); } } 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...