Submission #1134480

#TimeUsernameProblemLanguageResultExecution timeMemory
1134480JelalTkmBank (IZhO14_bank)C++20
100 / 100
526 ms3212 KiB
#include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; #define int long long int const int N = 1e6 + 10; const int md = 1e9 + 7; const int INF = 1e18; int32_t main(int32_t argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) { int n, m; cin >> n >> m; vector<int> a(n + 1), b(m + 1), pref(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } for (int j = 1; j <= m; j++) cin >> b[j]; vector<vector<bool>> dp(n + 1, vector<bool> ((1 << m) + 1)); for (int j = 0; j < (1 << m); j++) dp[0][j] = 1; string ans = "NO"; for (int j = 1; j < (1 << m); j++) { int num = 0, sm = 0; for (int k = 0; k < m; k++) if (((1 << k) & j)) { sm += b[k + 1]; } for (int i = 1; i <= n; i++) { if (sm == pref[i] && dp[i - 1][j]) { dp[i][j] = 1; } if (dp[i][j]) for (int k = 0; k < m; k++) { dp[i][(j | (1 << k))] = dp[i][j]; } if (i == n && dp[i][j]) ans = "YES"; } } cout << ans << '\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...