Submission #173714

#TimeUsernameProblemLanguageResultExecution timeMemory
173714touristBank (IZhO14_bank)C++14
71 / 100
1061 ms9464 KiB
#include <iostream> #include <time.h> #include <vector> using namespace std; #define ll long long #define sz(x) (int)x.size() #define pii pair < int, int > #define endl "\n" #define METH ios::sync_with_stdio(0); cin.tie(0); #define BEGIN cout << "BEGIN" << endl; #define END cout << "END" << endl; const int mod = 1e9 + 7; /// ANOTHER HASH MOD: 228228227 const int prime = 29; /// ANOTHER HASH PRIME: 997 const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8); int n, m; vector < short > a, b; short pre[1 << 20]; bool dp[21][1 << 20]; string int_to_bit(int x) { string res = ""; while (x) { if (x & 1) { res += "1"; } else { res += "0"; } x >>= 1; } while (res.size() < m) { res += "0"; } return res; } inline void read() { scanf("%d %d", &n, &m); a.resize(n + 1); b.resize(m + 1); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < m; i++) { scanf("%d", &b[i]); } } void calc(int mask, int cnt) { //cout << int_to_bit(mask) << " " << cnt << endl; if (cnt == n) { cout << "YES" << endl; exit(0); } if (dp[cnt][mask]) { return; } dp[cnt][mask] = 1; for (int sub = mask; sub != 0; sub = mask & (sub - 1)) { if (pre[sub] == a[cnt]) { calc(mask ^ sub, cnt + 1); } } } inline int solve() { for (int i = 0; i < (1 << m); i++) { int sum = 0; for (int j = 0; j < m; j++) { if (i >> j & 1) { sum += b[j]; } } pre[i] = sum; } calc((1 << m) - 1, 0); cout << "NO" << endl; } int main() { int t = 1; while (t--) { read(); solve(); } }

Compilation message (stderr)

bank.cpp: In function 'std::__cxx11::string int_to_bit(int)':
bank.cpp:34:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (res.size() < m) {
         ~~~~~~~~~~~^~~
bank.cpp: In function 'void read()':
bank.cpp:45:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<short int> >::value_type* {aka short int*}' [-Wformat=]
   scanf("%d", &a[i]);
                    ^
bank.cpp:48:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<short int> >::value_type* {aka short int*}' [-Wformat=]
   scanf("%d", &b[i]);
                    ^
bank.cpp: In function 'int solve()':
bank.cpp:81:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
bank.cpp: In function 'void read()':
bank.cpp:41: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:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
bank.cpp:48: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...