Maximal crossesProblem code: MAXCROSS |
The 'Clarification' in the problem statement has been updated on July 2nd at 6:15pm
On the matrix A sized n n, some cells were marked by crosses (X). For each cell (i,j) (with i the row index, j the column index), we define B(i,j) as the maximal number of continuous crosses going across the cell (i,j) in the same horizontal, vertical or diagonal; B(i,j)=0 if A(i,j) is empty ( '.' ). [ Empty cells are marked by '.'] .
Clarification:
Continuous crosses going across cell (i,j) in horizontal direction = x1 + x2 - 1
where x1 = highest possible x such that
j + x - 1<= n and A(i, j ... j + x - 1) are all 'X'
and x2 = highest possible x such that
j - x + 1 > 0 and A(i, j - x + 1...j) are all 'X'
Similarily we can extend the definition for vertical and diagonal directions.
Task
Given matrix A as input, calculate matrix B.
Input
- The first line contains the integer n.
- Then follow n lines , each containing n characters. The j-th character of the i-th line represents the cell (i,j) of the matrix A, with A(i,j)='X' if it contains a cross, or A(i,j)='.' if it is empty.
Output
Output n lines, each contains n integers, the j-th integer of the i-th line shows the value of B(i,j).
(Each integer on a same line must be separated by exactly one space character)
Example
Input:
10
..X....XX.
XX.X..XX.X
.....XX..X
.XXX..X.X.
.....X..XX
....X....X
X.X....XX.
.X...X.X.X
X.X..X....
..XXXXX.XX
Output:
0 0 2 0 0 0 0 3 3 0
2 2 0 2 0 0 3 3 0 2
0 0 0 0 0 3 3 0 0 2
0 3 3 3 0 0 3 0 2 0
0 0 0 0 0 3 0 0 2 2
0 0 0 0 3 0 0 0 0 3
4 0 3 0 0 0 0 2 3 0
0 4 0 0 0 3 0 3 0 2
3 0 4 0 0 3 0 0 0 0
0 0 5 5 5 5 5 0 2 2
Limitations
0<n 1 000
| Author: | anhdq |
| Date Added: | 4-05-2010 |
| Time Limit: | 1 - 1.5 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

@admin: Could you please tell
@admin:
Could you please tell me in which test case my solution fail?
thanks.