Guest User

Untitled

a guest
Mar 1st, 2016
588
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int N, P; cin >> N >> P;
  7.     int64_t apples = 0;
  8.     for(int i=0; i<N; ++i) {
  9.         string s; cin >> s;
  10.         if (s == "halfplus") apples |= (1LL << i);
  11.     }
  12.     // __builtin_popcount counts bits set to 1 in the binary representation of the number
  13.     int64_t gifts = __builtin_popcountll(apples);
  14.     cout << apples * P - gifts * P / 2 << endl;
  15.     return 0;
  16. }
RAW Paste Data