Boarding Queue

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

요약
1번부터 n번까지의 여행자가 격자에 놓여 있고 연속한 번호는 서로 인접한다. p번인 내가 탑승하기 전에 다른 여행자와 인접하게 되는 비율을 분수로 구한다.
난이도

보통10점 중 6점

유형
시뮬레이션, 구현, 배열, 그래프
정답자
아직 제출이 없습니다

문제

You are on your way to compete in The 2025 ICPC Asia Pacific Championship. Unfortunately, you are in the process of the worst part of flying: waiting in the boarding queue.

You are in a queue with nn travelers, numbered from 11 to nn ordered from the front of the queue to the back of the queue.

The boarding area is represented by a grid of rr rows and cc columns, where the rows are numbered from 11 to rr (top to bottom) and the columns are numbered from 11 to cc (left to right). Each traveler occupies exactly one distinct cell in the grid. Two travelers are adjacent if the cells they are in share an edge. Traveler tt and traveler t−1t − 1 are guaranteed to be adjacent, for any 2≤t≤n2 ≤ t ≤ n.

For example, Figure L.1 illustrates a possible location of the travelers. In this example, traveler 11 is adjacent to travelers 22 and 1010 but not adjacent to traveler 1111.

Figure L.1: Example location of the travelers.

At each boarding step, all of the following happen simultaneously:

  • The frontmost traveler in the queue, say traveler tt, boards the aircraft and leaves the boarding area.
  • For each t′t' (t+1≤t′≤nt + 1 ≤ t' ≤ n), traveler t′t' takes the cell that traveler t′−1t' − 1 was occupying immediately before the step.

For example, Figure L.2 illustrates the locations of the travelers after the first three boarding steps from the initial location above.

Figure L.2: Location of the travelers after 11, 22, and 33 boarding steps respectively.

You are traveler pp (that is, there are p−1p − 1 travelers in front of you). You know that your team coach is somewhere in the queue, but you do not know where. Assuming your team coach is equally likely to be any of travelers 11 to nn (except pp), you want to calculate the probability that you will be adjacent to your team coach at some point before you board the aircraft. Formally, you will be adjacent to traveler qq at some point before you board the aircraft if there exists an integer ss (0≤s<p0 ≤ s < p) such that traveler pp and traveler qq are adjacent after s boarding steps.

입력

The first line of input contains four integers rr, cc, nn, and pp (1≤r,c≤10001 ≤ r, c ≤ 1000; 2≤n≤r×c2 ≤ n ≤ r \times c; 1≤p≤n1 ≤ p ≤ n). Each of the next rr lines contains cc integers. The jj-th integer in the ii-th line denotes G_i,jG\_{i,j} (0≤G_i,j≤n0 ≤ G\_{i,j} ≤ n), where a non-zero value of G_i,jG\_{i,j} means that traveler G_i,jG\_{i,j} initially occupies the cell at row ii and column jj of the boarding area, while a zero value of G_i,jG\_{i,j} means that no traveler occupies the cell. Across all pairs (i,j)(i, j), each of the integers 11 to nn appears exactly once in G_i,jG\_{i,j}. The input guarantees that traveler tt and traveler t−1t − 1 are adjacent, for all 2≤t≤n2 ≤ t ≤ n.

출력

Output a fraction in the x/yx/y format indicating the probability that you will be adjacent to your team coach at some point before you board the aircraft. The value of yy must be equal to n−1n − 1. Note that there must not be spaces between the integers and the / delimiter.

예제2

  1. 예제 1

    입력
    4 5 11 2
    11 0 0 0 0
    10 1 2 0 0
    9 0 3 4 0
    8 7 6 5 0
    
    예상 출력
    3/10
    
  2. 예제 2

    입력
    1 7 7 6
    1 2 3 4 5 6 7
    
    예상 출력
    2/6