fork download
  1. class Solution {
  2. public:
  3.  
  4. bool check(vector<int>&bits, int num) {
  5. for (auto it: bits) {
  6. if (num & (1<<it)) return false;
  7. }
  8. return true;
  9. }
  10.  
  11. int calculate(vector<int>& nums, vector<int>&bits) {
  12. long long curr_res = (1ll<<31) - 1;
  13. int partitions = 0;
  14. for (int i = 0; i < nums.size(); i++) {
  15. curr_res &= nums[i];
  16. if (check(bits, curr_res)) {
  17. partitions++;
  18. curr_res = (1ll<<31) - 1;
  19. }
  20. }
  21. return nums.size() - partitions;
  22. }
  23.  
  24. int calculateOR(vector<int>& bits) {
  25. long long curr = (1ll<<31) - 1;
  26. for (auto it: bits) {
  27. curr ^= (1<<it);
  28. }
  29. return curr;
  30. }
  31.  
  32. int minOrAfterOperations(vector<int>& nums, int k) {
  33. vector<int> bits;
  34. for (int bit = 30; bit >= 0; bit--) {
  35. bits.push_back(bit);
  36. if (calculate(nums, bits) > k) {
  37. bits.pop_back();
  38. }
  39. }
  40. return calculateOR(bits);
  41. }
  42. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:16: error: ‘vector’ has not been declared
     bool check(vector<int>&bits, int num) {
                ^~~~~~
prog.cpp:4:22: error: expected ‘,’ or ‘...’ before ‘<’ token
     bool check(vector<int>&bits, int num) {
                      ^
prog.cpp:11:19: error: ‘vector’ has not been declared
     int calculate(vector<int>& nums, vector<int>&bits) {
                   ^~~~~~
prog.cpp:11:25: error: expected ‘,’ or ‘...’ before ‘<’ token
     int calculate(vector<int>& nums, vector<int>&bits) {
                         ^
prog.cpp:24:21: error: ‘vector’ has not been declared
     int calculateOR(vector<int>& bits) {
                     ^~~~~~
prog.cpp:24:27: error: expected ‘,’ or ‘...’ before ‘<’ token
     int calculateOR(vector<int>& bits) {
                           ^
prog.cpp:32:30: error: ‘vector’ has not been declared
     int minOrAfterOperations(vector<int>& nums, int k) {
                              ^~~~~~
prog.cpp:32:36: error: expected ‘,’ or ‘...’ before ‘<’ token
     int minOrAfterOperations(vector<int>& nums, int k) {
                                    ^
prog.cpp: In member function ‘bool Solution::check(int)’:
prog.cpp:5:23: error: ‘bits’ was not declared in this scope
         for (auto it: bits) {
                       ^~~~
prog.cpp:5:23: note: suggested alternative: ‘it’
         for (auto it: bits) {
                       ^~~~
                       it
prog.cpp:6:17: error: ‘num’ was not declared in this scope
             if (num & (1<<it)) return false;
                 ^~~
prog.cpp:6:17: note: suggested alternative: ‘enum’
             if (num & (1<<it)) return false;
                 ^~~
                 enum
prog.cpp: In member function ‘int Solution::calculate(int)’:
prog.cpp:14:29: error: ‘nums’ was not declared in this scope
         for (int i = 0; i < nums.size(); i++) {
                             ^~~~
prog.cpp:14:29: note: suggested alternative: ‘enum’
         for (int i = 0; i < nums.size(); i++) {
                             ^~~~
                             enum
prog.cpp:16:23: error: ‘bits’ was not declared in this scope
             if (check(bits, curr_res)) {
                       ^~~~
prog.cpp:21:16: error: ‘nums’ was not declared in this scope
         return nums.size() - partitions;
                ^~~~
prog.cpp:21:16: note: suggested alternative: ‘enum’
         return nums.size() - partitions;
                ^~~~
                enum
prog.cpp: In member function ‘int Solution::calculateOR(int)’:
prog.cpp:26:23: error: ‘bits’ was not declared in this scope
         for (auto it: bits) {
                       ^~~~
prog.cpp:26:23: note: suggested alternative: ‘it’
         for (auto it: bits) {
                       ^~~~
                       it
prog.cpp: In member function ‘int Solution::minOrAfterOperations(int)’:
prog.cpp:33:9: error: ‘vector’ was not declared in this scope
         vector<int> bits;
         ^~~~~~
prog.cpp:33:16: error: expected primary-expression before ‘int’
         vector<int> bits;
                ^~~
prog.cpp:35:13: error: ‘bits’ was not declared in this scope
             bits.push_back(bit);
             ^~~~
prog.cpp:35:13: note: suggested alternative: ‘bit’
             bits.push_back(bit);
             ^~~~
             bit
prog.cpp:36:27: error: ‘nums’ was not declared in this scope
             if (calculate(nums, bits) > k) {
                           ^~~~
prog.cpp:36:27: note: suggested alternative: ‘enum’
             if (calculate(nums, bits) > k) {
                           ^~~~
                           enum
prog.cpp:36:41: error: ‘k’ was not declared in this scope
             if (calculate(nums, bits) > k) {
                                         ^
prog.cpp:40:28: error: ‘bits’ was not declared in this scope
         return calculateOR(bits);
                            ^~~~
stdout
Standard output is empty