아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

LaLa and Lamp

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

요약
삼각형 격자의 전구 상태가 주어질 때, 세 방향의 행 전체를 뒤집는 마법만으로 모든 전구를 끌 수 있는지 판정한다.
난이도

보통10점 중 7점

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

문제

When LaLa\color{blue}{\text{LaLa}} laid down on her pet Leo\color{brown}{\text{Leo}}'s back to fall asleep, she noticed that the lamp is all messed up, which must have been the act of her sister LiLi\color{purple}{\text{LiLi}}.

The lamp can be modeled as a regular triangular grid where each cell contains a bulb which is either on or off.

LaLa\color{blue}{\text{LaLa}} wants to turn off the lamp (that is, set the state of all bulbs to off). LaLa\color{blue}{\text{LaLa}} can pick any of the three directions parallel to the side of a lamp, pick any row parallel to that direction, and then flip the state of all the bulbs in the row (on to off and off to on) with her magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}. LaLa\color{blue}{\text{LaLa}} also could just walk over to the lamp and manually turn every bulb off, but she would prefer not to.

Write a program that determines whether LaLa\color{blue}{\text{LaLa}} can turn off the lamp with her magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}.

입력

The input is given in the following format:

NN

S_0S\_0

S_1S\_1

⋮\vdots

S_N−1S\_{N-1}

where NN is the number of bulbs in a side of the lamp, and S_iS\_i is the binary string of length i+1i+1 representing the initial states of bulbs in the ii-th row, where the jj-th character of S_iS\_i is '1' if and only if the jj-th bulb is on.

The input satisfies the following constraint:

  • NN is an integer.
  • 2≤N≤2,0002 \le N \le 2\\,000

출력

If LaLa\color{blue}{\text{LaLa}} can turn off the lamp with magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}, print a single string "Yes". Otherwise, print a single string "No". You may print each character in either case (lower or upper).

힌트

The following illustrates a sequence of magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}} LaLa\color{blue}{\text{LaLa}} should cast to turn off the lamp given in the sample. Empty circles denote the bulbs that are off, yellow circles denote the bulbs that are on, and red line is the choosen row for magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}.

Step 0Step 1Step 2
Step 3Step 4Step 5
Step 6

예제1

  1. 예제 1

    입력
    6
    0
    00
    000
    0110
    00100
    000000
    
    예상 출력
    Yes