Company: MediaNet_23july
Difficulty: medium
Help Your Master 2 Problem Description A field agent was captured during a stakeout and is now locked inside a facility ringed with security cameras. The only way to disable every camera at once is to key in a numeric access code, and that code turns out to be the answer to the grid puzzle described below. Help the agent work out the code. You are given a matrix of order N×N. Each cell in the matrix has a value A[i][j] (0≤i,j<N) that is either positive or equal to -1 (representing a blocked cell). Cells that are not blocked hold distinct values. You can move from a cell to any adjacent cell in any direction (up, down, left or right), as long as no blockage stands between them. For any cell A[i][j], its sed-value S[i][j] is defined as the sum of the values of cells A[x][y] that are a multiple of A[i][j] but cannot be reached from A[i][j]. Blocked cells always have a sed-value of -1. The access code P is the sum of the sed-values of every cell, taken modulo 1000000007. Input Format: T