Fortune Telling 3

시간 제한6초메모리 제한2048 MB

요약
안나가 900개의 비트를 하나씩 보며 각 카드를 테이블에 끼워 넣거나 버릴 수 있고, 브루노는 마지막 카드 배열만 보고 1의 총개수를 알아내야 한다.
난이도

어려움10점 중 9점

유형
그리디, 조합론, 수학, 구현
정답자
아직 제출이 없습니다

문제

Anna and Bruno like fortune-telling and enjoy playing various styles of fortune-telling together. Today, they will play fortune-telling using cards, which is described below. They will play it for QQ times.

  1. They prepare many cards with 00 or 11 written on each one, shuffle them, and pile them up on the deck.

  2. Anna draws NN (=900= 900) cards from the deck, one at a time. Anna and Bruno know the value of NN. Every time she draws a card, she decides whether to discard the card or put the card on the table.

    • If she selects to put the card on the table, she inserts the card into the sequence of cards on the table.
    • More formally, when there are l cards on the table, she designates a non-negative integer xx (0≤x≤l0 ≤ x ≤ l) and puts the card immediately right to the xx-th leftmost card on the table. In the case of x=0x = 0, she puts the card on the leftmost of the sequence of cards on the table.
  3. The procedure for Anna finishes when she draws and processes NN cards. The result of the fortune-telling is the number of cards with 11 among the NN cards.

  4. After Anna finishes her procedure, Bruno sees the sequence of cards on the table. Using the information, he needs to guess the result of the fortune-telling. If he guesses correctly, the fortune-telling is a success.

The fortune-telling is considered more proficient when fewer cards are on the table. Write a program to implement Anna’s and Bruno’s strategies to succeed in all QQ fortune tellings. In this task, the fewer cards Anna puts on the table, the higher the score will be.

제한

All the input data satisfy the following conditions.

  • 1≤Q≤1001 ≤ Q ≤ 100.
  • N=900N = 900.
  • A_i,jA\_{i, j} is either 00 or 11 (1≤i≤Q1 ≤ i ≤ Q, 1≤j≤N1 ≤ j ≤ N).

예제

이 문제는 공개된 예제가 없습니다.