Intersegment Activation

시간 제한2초메모리 제한1024 MB

요약
매 라운드 보이는 칸 수만 보고하면서, 각 구간을 덮는 장벽을 뒤집어 모든 칸이 보이도록 만든다.
난이도

어려움10점 중 8점

유형
구간, 구현, 완전 탐색, 그리디
정답자
아직 제출이 없습니다

문제

This is an interactive problem.

There is an array of nn cells, numbered from 11 to nn. For each pair of integers (i,j)(i, j), where 1≤i≤j≤n1 \le i \le j \le n, there is a barrier covering all cells from ii to jj, inclusive. Each barrier is either active or inactive. A cell is visible if there are no active barriers that cover it. Otherwise, the cell is invisible.

The state of each barrier is unknown to you. All you can observe is the number of visible cells. But you can flip the state of any barrier: if it's active, it turns inactive, and the other way around. Your task is to make all barriers inactive, so that all cells become visible.

힌트

In the example, initially, only two barriers, (1,2)(1, 2) and (2,3)(2, 3), are active. These two barriers cover all three cells, so kk is equal to 0 in the first round.

  • After flipping the (2,2)(2, 2) barrier, there are now three active barriers, and still k=0k = 0 visible cells.
  • After flipping the (1,2)(1, 2) barrier, cell 11 becomes visible, so now there is k=1k = 1 visible cell.
  • After flipping the (2,3)(2, 3) barrier, cell 33 also becomes visible. The only invisible cell now is 22, covered by the only active barrier, (2,2)(2, 2), and there are k=2k = 2 visible cells.
  • After flipping the (2,2)(2, 2) barrier, all barriers are now inactive, and all cells are visible. After reading k=3k = 3, the program terminates.

예제1

  1. 예제 1

    입력
    3
    0
    
    0
    
    1
    
    2
    
    3
    
    예상 출력
    
    
    2 2
    
    2 3
    
    1 2
    
    2 2