Painting the Balls
Time limit2sMemory limit512 MB
Given M range-painting operations used in order with unknown colors, count how many distinct final black/white ball colorings are possible.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, Combinatorics
- Solved
- No attempts yet
Problem
balls sit in a row. A ball can be painted black or white, and every ball is white at the start. The leftmost ball is ball 1, and the balls are numbered in order from left to right.
Today you want to paint the balls. A machine does the painting, and it reads two integers and . The machine paints ball through ball entirely in one color, either white or black.
You used the machine times in total, and you know every and you gave it. You forgot which color each use painted.
Write a program that counts how many color combinations can appear after all uses of the machine.
Input
The first line contains the number of balls and the number of machine uses . (, )
Each of the next lines contains the and given to the machine, in the order the machine was used. ()
Output
Print the number of color combinations that can appear. The answer is at most .