josiftepe

Untitled

Nov 28th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. using namespace std;
  5. typedef long long ll;
  6. int power(int a, int b) {
  7.     int ret = 1;
  8.     while(b > 0) {
  9.         ret *= a;
  10.         --b;
  11.     }
  12.     return ret;
  13. }
  14. int main()
  15. {
  16.     ios_base::sync_with_stdio(false);
  17.     int h, w, k;
  18.     cin >> h >> w >> k;
  19.     vector<int> blocks(31);
  20.     for(int i = k; i >= 0; --i) {
  21.         int power_of_two = power(2, i);
  22.         int tmp_w = w;
  23.         int sum = 0;
  24.         int cnt_blocks = 1;
  25.         while(tmp_w > 0) {
  26.             if(tmp_w >= power_of_two) {
  27.                 sum += (tmp_w / power_of_two) * cnt_blocks;
  28.                 tmp_w %= power_of_two;
  29.             }
  30.             power_of_two /= 2;
  31.             cnt_blocks *= 2;
  32.         }
  33.         blocks[i] = sum;
  34.     }
  35.     ll ret = 0;
  36.    
  37.     while(h > 0) {
  38.         if(h >= power(2, k)) {
  39.             ret += (h / power(2, k)) * blocks[k];
  40.             h %= power(2, k);
  41.         }
  42.         --k;
  43.     }
  44.     cout << ret << endl;
  45.  
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment