Submission #171934

#TimeUsernameProblemLanguageResultExecution timeMemory
171934davitmargBank (IZhO14_bank)C++17
100 / 100
732 ms64364 KiB
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <unordered_map> #include <set> #include <queue> #include <iomanip> #include <bitset> #include <stack> #include <cassert> #include <iterator> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; const int N = 25; int n, m, dp[N][(1 << 20) + 5]; int a[N], b[N], sum[(1 << 20) + 5]; vector<int> masks[N * 1003]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; for (int mask = 0; mask < (1 << m); mask++) { for (int i = 0; i < m; i++) if (((1 << i) & mask)) sum[mask] += b[i + 1]; masks[sum[mask]].PB(mask); //cout << mask << " = " << sum[mask] << endl; } dp[0][0] = 1; LL pr = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < masks[a[i]].size(); j++) { int mask = masks[a[i]][j]; for (int x = 0; x < masks[pr].size(); x++) { int s = masks[pr][x]; if (dp[i - 1][s] && (mask & s) == 0) dp[i][mask | s] = 1; } } //for (int mask = 0; mask < (1 << m); mask++) // cout << i << " : " << mask << " = " << dp[i][mask] << endl; pr += a[i]; } int ans = 0; for (int mask = 0; mask < (1 << m); mask++) ans += dp[n][mask]; if (ans) cout << "YES" << endl; else cout << "NO" << endl; return 0; } /* 2 4 9 10 5 4 5 5 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7 */

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:52:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < masks[a[i]].size(); j++)
                         ~~^~~~~~~~~~~~~~~~~~~~
bank.cpp:55:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int x = 0; x < masks[pr].size(); x++)
                             ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...