Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement