Submission #887700

#TimeUsernameProblemLanguageResultExecution timeMemory
887700duckindogBank (IZhO14_bank)C++14
52 / 100
318 ms752 KiB
//from duckindog wth depression #include<bits/stdc++.h> using namespace std; const int N = 21, M = (1 << 20); int n, m; int a[N], b[N]; int f[M]; int d[1010][N]; bool sub1(int i, int j) { if (i == 0) return 1; if (i < 0) return 0; int &ret = d[i][j]; if (ret > -1) return ret; ret = 0; for (int t = j + 1; t <= m; ++t) ret |= sub1(i -= b[j], t); return ret; } int32_t main() { cin.tie()->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= m; ++i) cin >> b[i]; if (n == 1) { memset(d, -1, sizeof d); cout << (sub1(a[1], 0) == 1 ? "YES" : "NO"); return 0; } for (int mask = 1; mask <= (1 << m) - 1; ++mask) { for (int s = 0; s < mask; ++s) { if (f[s] == n) continue; if ((s | mask) != mask) continue; int t = ((s & mask) ^ mask); int val = 0; for (int i = 1; i <= m; ++i) if ((t >> i - 1) & 1) val += b[i]; if (val == a[f[s] + 1]) f[mask] = max(f[mask], f[s] + 1); } } for (int mask = 1; mask <= (1 << m) - 1; ++mask) { if (f[mask] == n) { cout << "YES"; return 0; } } cout << "NO"; }

Compilation message (stderr)

bank.cpp: In function 'bool sub1(int, int)':
bank.cpp:17:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   17 |   if (ret > -1) return ret; ret = 0;
      |   ^~
bank.cpp:17:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   17 |   if (ret > -1) return ret; ret = 0;
      |                             ^~~
bank.cpp: In function 'int32_t main()':
bank.cpp:47:48: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   47 |       for (int i = 1; i <= m; ++i) if ((t >> i - 1) & 1) val += b[i];
      |                                              ~~^~~
bank.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...