Submission #17893

#TimeUsernameProblemLanguageResultExecution timeMemory
17893chromeBank (IZhO14_bank)C++98
71 / 100
1066 ms6980 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define foreach(it, S) for (__typeof (S.begin()) it = S.begin(); it != S.end(); it++) #define all(x) x.begin(), x.end() #define endl '\n' #define _ ios_base :: sync_with_stdio(false); cin.tie(NULL); #ifdef inputf #define fname "" #else #define fname "" // <- Here #endif const double eps = 1e-9; const int MaxN = int(2e5) + 256; const int MOD = int(1e9) + 7; template <typename T> inline T gcd(T a, T b) { return b ? gcd (b, a % b) : a; } inline bool Palindrome(const string& s) { return equal(s.begin(), s.end(), s.rbegin()); } int n, m; int a[50], b[50]; bool calced[20][1 << 20]; bool d[20][1 << 20]; bool f(int i, int msk) { if (i == n) return true; if (calced[i][msk]) return d[i][msk]; calced[i][msk] = true; bool res = false; for (int nxt = msk; nxt > 0; nxt = (nxt - 1) & msk) { int nxtmsk = nxt ^ msk; int cur = 0; for (int i = 0; i < m; ++i) if (nxt >> i & 1) cur += b[i]; if (cur == a[i]) { if (f(i + 1, nxtmsk)) { res = true; break; } } } return d[i][msk] = res; } int main() { // _ #ifdef lcl freopen(fname".in", "r", stdin); freopen(fname".out", "w", stdout); #endif scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%d", a + i); for (int i = 0; i < m; ++i) scanf("%d", b + i); puts(vector<string>{"NO", "YES"}[f(0, (1 << m) - 1)].c_str()); return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a + i);
   ~~~~~^~~~~~~~~~~~~
bank.cpp:70: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...