Submission #90725

#TimeUsernameProblemLanguageResultExecution timeMemory
90725daniel_02Bank (IZhO14_bank)C++11
71 / 100
1062 ms2792 KiB
#include <bits/stdc++.h> #define fr first #define pb push_back #define sc second #define ll long long using namespace std; const int N = 23; int a[N], b[N]; bool dp[N][(1 << 20) + 7]; vector<int>v; vector<pair<int, int>>v1; vector<pair<int, int>>v2; main() { int n, m, x; cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= m; i++) { scanf("%d", &b[i]); } for (int msk = 1; msk < (1 << m); msk++) { int sm = 0; for (int i = 0; i < m; i++) { if (msk & (1 << i)) { sm += b[i + 1]; } } if (sm == a[1]) { //cout << 1 << " " << msk << endl; dp[1][msk] = 1; } } for (int msk = 0; msk < (1 << (m / 2)); msk ++) { int sm = 0; for (int i = 0; i < m / 2; i++) { if (msk & (1 << i)) { sm += b[i + 1]; } } v1.pb({sm, msk}); } for (int msk = 0; msk < (1 << ((m + 1) / 2)); msk ++) { int sm = 0; for (int i = 0; i < (m + 1) / 2; i++) { if (msk & (1 << i)) { sm += b[i + 1]; } } v2.pb({sm, msk * (1 << (m / 2))}); } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); for (int i = 2; i <= n; i++) { for (int msk = 1; msk < (1 << m); msk++) { if (!dp[i - 1][msk])continue; for (int j = 0; j < m; j++) { if (!(msk & (1 << j))) { v.pb(j + 1); } } int sz = v.size(); for (int msk1 = 1; msk1 < (1 << sz); msk1++) { int sm = 0; for (int j = 0; j < sz; j++) { if (msk1 & (1 << j)) { sm += b[v[j]]; } } if (sm == a[i]) { int tmp = msk; for (int j = 0; j < sz; j++) { if (msk1 & (1 << j)) { tmp = (tmp | (1 << (v[j] - 1))); //cout << j << " " << v[j] << endl; } } //cout << i << " " << msk << " " << tmp << endl; dp[i][tmp] = 1; } } v.clear(); } } for (int msk = 1; msk < (1 << m); msk++) { if (dp[n][msk]) { puts("YES"); return 0; } } puts("NO"); }

Compilation message (stderr)

bank.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
bank.cpp: In function 'int main()':
bank.cpp:20:12: warning: unused variable 'x' [-Wunused-variable]
  int n, m, x;
            ^
bank.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
bank.cpp:30:8: 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...