SHARE
TWEET

Untitled

a guest Dec 15th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. short c[10002];
  5.  
  6. int P2 (long long &x)
  7. {
  8.     int t = 0;
  9.    
  10.     while(x % 2 == 0)
  11.     {
  12.        x = x / 2;
  13.        ++t;
  14.     }
  15.    
  16.     return t;
  17. }
  18.  
  19. int main()
  20. {
  21.     ifstream fin ("memory006.in");
  22.     ofstream fout("memory006.out");
  23.    
  24.     int n, k, t = 0, pf = 0, sum = 0, s = 0, pi = 1;
  25.  
  26.     fin >> n >> k;
  27.     long long x;
  28.     for (int i = 1; i <= n; i++)
  29.     {
  30.         fin >> x;
  31.         t = P2(x);
  32.         if (x == 1) // putere a lui 2
  33.         {
  34.             pf = (pf + 1) % 10001;
  35.             c[pf] = t;
  36.             sum = sum + t;
  37.             if (sum == k)
  38.                 s++;
  39.             if (sum > k)
  40.             {
  41.                 while(sum > k)
  42.                 {
  43.                     sum = sum - c[pi];
  44.                     pi = (pi + 1) % 10001;
  45.                 }
  46.                 if(sum == k)
  47.                     s++;
  48.             }
  49.         }
  50.         else
  51.         {
  52.             pf = sum = 0;
  53.             pi = 1;
  54.         }
  55.     }
  56.    
  57.     fout << s;
  58.    
  59.     return 0;
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top