Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class DancingBits
- {
- static void Main()
- {
- int lenght = int.Parse(Console.ReadLine());
- int digits = int.Parse(Console.ReadLine());
- int previousBit = 0;
- int count = 0;
- int result = 0;
- for (int i = 0; i < digits; i++)
- {
- int number = int.Parse(Console.ReadLine());
- for (int j = 30; j >= 0; j--)
- {
- int mask = 1 << j;
- int bit = number & mask;
- bit = bit >> j;
- if (mask > number)
- {
- continue;
- }
- else if (lenght == 1)
- {
- if (bit != previousBit)
- {
- count = 1;
- result++;
- previousBit = bit;
- }
- else if (bit == previousBit && count == 1)
- {
- count = 0;
- result--;
- }
- }
- else if (bit == previousBit && count == lenght)
- {
- if (j == lenght - 1 && i == digits - 1)
- {
- count++;
- }
- else
- {
- count = 1;
- }
- }
- else if (bit != previousBit && count == lenght)
- {
- count = 1;
- result++;
- previousBit = bit;
- }
- else if (bit == previousBit && count < lenght)
- {
- if (count == lenght - 1 && i == digits - 1 && j == 0)
- {
- result++;
- }
- else
- {
- count++;
- }
- }
- else if (bit != previousBit && count < lenght)
- {
- count = 1;
- previousBit = bit;
- }
- }
- }
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement