Discussion Club 2
Time limit20sMemory limit1024 MB
Count the ways to split m members seated in a circle into two contiguous arcs so that every view held by someone appears in both teams.
- Level
Medium6 of 10
- Topics
- Two pointers, Sliding window, Bit manipulation, Array
- Solved
- No attempts yet
Problem
We visit the Bajtocki Discussion Club again. The club has members, and each member has stated their views on fundamental questions. The exact wording of the questions does not matter. Each question has one of two possible answers (for example, coffee or tea?). A person's views can be encoded as a string of bits, which read as a binary number gives an integer from 0 to . No two club members have the same views.
Today the club meets, and members attend. Each has already taken a seat at a round table. The members want to split into two teams to prepare for the main topic in advance. To keep things orderly, each team must consist of members sitting in consecutive seats around the table. For a productive discussion, every team must cover all views: for each fundamental question and each possible answer, if some member of the first team holds that view, then some member of the second team must also hold it.
Write a program that counts the number of ways to split the members into two teams.
Input
The first line contains two integers and (, ), the number of fundamental questions and the number of members at the meeting. The second line contains pairwise distinct integers from 0 to , describing the views of the members in order around the table.
Output
Print one integer, the number of ways to split the members into two teams that satisfy the conditions.
Constraints