fork download
  1. int n, k;
  2. cin >> n >> k;
  3. vector<int> a(n);
  4. for (auto &x : a) cin >> x;
  5.  
  6. int res = (k == 0);
  7. int sum = 0;
  8.  
  9. for (int mask = 1; mask < (1 << n); mask++) {
  10. int diff = mask^(mask-1);
  11. while (diff != 0) {
  12. int idx = __builtin_ctz(diff); // idx = index on which mask and mask-1 differ(they could differ on many indices)
  13. diff ^= (1 << idx);
  14. if ((mask >> idx) & 1) { // mask has this bit set, but mask-1 hadn't
  15. sum += a[idx];
  16. } else { // mask hasn't this bit set, but mask-1 had
  17. sum -= a[idx];
  18. }
  19. }
  20. res += (sum == k);
  21. }
  22.  
  23. cout << res;
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:1: error: ‘cin’ does not name a type
 cin >> n >> k;
 ^~~
prog.cpp:3:1: error: ‘vector’ does not name a type
 vector<int> a(n);
 ^~~~~~
prog.cpp:4:1: error: expected unqualified-id before ‘for’
 for (auto &x : a) cin >> x;
 ^~~
prog.cpp:9:1: error: expected unqualified-id before ‘for’
 for (int mask  = 1;  mask < (1 << n); mask++) {
 ^~~
prog.cpp:9:22: error: ‘mask’ does not name a type
 for (int mask  = 1;  mask < (1 << n); mask++) {
                      ^~~~
prog.cpp:9:39: error: ‘mask’ does not name a type
 for (int mask  = 1;  mask < (1 << n); mask++) {
                                       ^~~~
prog.cpp:23:1: error: ‘cout’ does not name a type
 cout << res;
 ^~~~
stdout
Standard output is empty