Submission #37868

#TimeUsernameProblemLanguageResultExecution timeMemory
37868TalantBank (IZhO14_bank)C++14
100 / 100
126 ms11024 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define OK puts("OK"); #define pb push_back #define mk make_pair using namespace std; typedef long long ll; const ll inf = (ll)1e18 + 7; const ll N = (ll)1e6 + 7; int n,m; int a[21],b[21]; int dp[21][1 << 20]; int t[1 << 20],sum1; vector <int> vec[21],vec1,vec2; int p[N]; int us[N],us1[N]; int used[N]; int main () { cin >> n >> m; for (int i = 1; i <= n; i ++) { scanf ("%d", &a[i]); us1[a[i]] ++; } for (int i = 0; i < m; i ++) { scanf ("%d", &b[i]); us[b[i]] ++; } for (int i = 1; i <= n; i ++) { if (us[a[i]] > 0 && us1[a[i]] > 0) us[a[i]] --,us1[a[i]] --; else vec2.pb(a[i]); } for (int i = 0; i < m; i ++) { for (int j = 1; j <= us[b[i]]; j ++) { sum1 += b[i]; vec1.pb(b[i]); } us[b[i]] = 0; } n = vec2.size(); m = vec1.size(); for (int i = 1; i <= n; i ++) a[i] = vec2[i - 1]; for (int i = 0; i < m; i ++) b[i] = vec1[i]; for (int i = 1; i <= n; i ++) p[i] = p[i - 1] + a[i]; for (int i = 0; i < (1 << m); i ++) { int sum = 0; for (int j = 0; j < m; j ++) if (i & (1 << j)) sum += b[j]; t[i] = sum; } dp[1][0] = 1; vec[1].pb(0); if (p[n] > sum1) { cout << "NO"; return 0; } if (n * 2 > m) { cout << "NO"; return 0; } for (int i = 1; i <= n; i ++) { for (int j = 0; j < (1 << m); j ++) { if (t[j] == a[i]) { if (n == 1) { cout << "YES"; return 0; } for (int k = 0; k < vec[i].size(); k ++) { if (!(vec[i][k] & j)) { int q = sum1 - t[(vec[i][k] | j)]; if (q >= p[n] - p[i] && (m - __builtin_popcount(vec[i][k] | j)) >= n - i) { if (dp[i + 1][vec[i][k] | j] != 1) vec[i + 1].pb(vec[i][k] | j); dp[i + 1][vec[i][k] | j] = 1; if (n <= i) { cout << "YES" << endl; return 0; } } else break; } } } } } if (n == 1) { cout << "NO" << endl; return 0; } for (int i = 0; i < (1 << m); i ++) { if (dp[n + 1][i] == 1) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:91:51: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                                 for (int k = 0; k < vec[i].size(); k ++) {
                                                 ~~^~~~~~~~~~~~~~~
bank.cpp:29:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d", &a[i]);
                 ~~~~~~^~~~~~~~~~~~~
bank.cpp:34:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d", &b[i]);
                 ~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...