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

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

Index Case

면접 대비

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

요약
순환 세포 자동자 규칙과 목표 상태가 주어질 때, 한 단계 전에 존재할 수 있는 이전 상태가 있는지 판별한다.
난이도

보통10점 중 6점

유형
동적 계획법, 완전 탐색, 시뮬레이션, 구현
정답자
아직 제출이 없습니다

문제

The epidemiologist W. Andy wants to find the index case of an ongoing crisis. To do this, he modelled the city of the outbreak and its nn residents with a cellular automaton. The city is represented by nn cells numbered from 11 to nn and each cell has two neighbouring cells, one to its left and one to its right. The left neighbour of cell ii is cell i−1i-1 and the right neighbour is cell i+1i+1. Additionally, the left neighbour of cell 11 is cell nn and the right neighbour of cell nn is cell 11. Thus, the city and the corresponding automaton form a simple cycle.

Each cell contains an integer between 11 and mm which represents how likely it is that this person is infected. Since the virus can only be transmitted by personal contact, the value in the iith cell on day dd only depends on the values of its neighbours and itself on the previous day. If we denote this value by s_d\[i]s\_{d}\[i], then the outbreak can be simulated by a function ff using the formula: \[s_{d}[i]=f\big(s_{d-1}[i-1],s_{d-1}[i],s_{d-1}[i+1]\big).\] Note that as the city is cyclic both i+1i+1 and i−1i-1 are calculated modulo nn.

Andy wants to find the index case, so he first has to find s_0s\_0, the state of the city on day zero. This poses a problem, however, as it is not known on which day the crisis started. Right now, Andy believes that he accomplished the task and found the state s_0s\_0, but you are not convinced. Therefore, you want to check if there may be a state previous to the initial state proposed by Andy, i.e. whether there exists any state s_−1s\_{-1} that gets transformed into s_0s\_0 by applying ff.

입력

The input consists of:

  • One line with two integers nn and mm (3≤n≤200,2≤m≤10)(3\leq n \leq 200, 2\leq m \leq 10), the number of cells and the number of states.
  • m3m^3 lines describing the values f(x,y,z)f(x,y,z) (1≤f(x,y,z)≤m1 \le f(x,y,z) \le m for each 1≤x,y,z≤m1 \le x,y,z \le m) of the function ff modelling the automaton. The values are given in lexicographic order of the arguments: The first value is f(1,1,1)f(1,1,1), the next is f(1,1,2)f(1,1,2), and so on until f(1,1,m)f(1,1,m), followed by f(1,2,1)f(1,2,1) and so forth. The last value is f(m,m,m)f(m,m,m).
  • One line with nn integers s_0\[1],…,s_0\[n]s\_0\[1],\dots,s\_0\[n] (1≤s_0\[i]≤m1 \le s\_0\[i] \le m for each ii), the initial state that has been proposed by Andy.

출력

Output yes if there exists at least one possible previous state and no otherwise.

예제3

  1. 예제 1

    입력
    4 2
    1
    2
    1
    2
    2
    1
    2
    1
    1 2 1 2
    
    예상 출력
    yes
    
  2. 예제 2

    입력
    6 2
    1
    2
    1
    2
    2
    1
    2
    1
    1 2 1 2 1 2
    
    예상 출력
    no
    
  3. 예제 3

    입력
    10 2
    1
    2
    1
    1
    2
    2
    2
    2
    1 2 2 2 1 2 1 2 1 2
    
    예상 출력
    yes