Maximal crossesProblem code: MAXCROSS |
All submissions for this problem are available.
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

Fetching successful submissions

in the problem statement
in the problem statement 'Clarification' , it should be A(i,j......j+x-1) are all 'X' instead of B(i,j...j+x-1) are all 'X'
which one of them are count
which one of them are count for 'X' in 1,7?
Can somebody clarify the
Can somebody clarify the clarification :-o
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 B(i, j ... j + x - 1) are all 'X'
and x2 = highest possible x such that
j - x + 1 > 0 and B(i, j - x + 1...j) are all 'X'
Is anti-digonal allowed>?
Is anti-digonal allowed>?
@Mahesh Chandra Sharma: both
@Mahesh Chandra Sharma: both two diagonal , and /, is ok ;-)
instead of writing our output
instead of writing our output to the console can we write it to a file?? if yes... then wat shud be the name of that file???
Continuous crosses going
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 B(i, j ... j + x - 1) are all 'X'
and x2 = highest possible x such that
j - x + 1 > 0 and B(i, j - x + 1...j) are all 'X'
i don't understand this part of the question.. can somebody help me out??
there is exactly 1 space
there is exactly 1 space between 2 integers in same line..wat abt the last integer in a line..whether there is a space after that also or not??and the output has to be terminated with "n" or not??plzz someone who has got AC explain the output format..
read "n" as new line..sorry
read "n" as new line..sorry fr the mistake..
Can anybody plz explain the
Can anybody plz explain the example in the problem statement?
I can't seem to figure out on what basis the output is derived from the input.
@Everyone: Please constrain
@Everyone: Please constrain your comments to clarification requests. All other comments that have been completely unnecessary have been removed.
The diagonals are considered
The diagonals are considered as one or as separate when calculating the maximum?
Separate, in the same way
Separate, in the same way that horizontal + vertical are separate.
this is bad.. i had to write
this is bad.. i had to write the whole code in C to make this work within time limit... plzz see to this.. i mean this is not fair at all..
Are there ONLY n rows and n
Are there ONLY n rows and n columns in the input or
can there be more than n but we should read only n?
Please I need a direct answer. 1 or 2.
'X' should be in Ucase or
'X' should be in Ucase or Lcase ?!!
@N Mamba: Upper :-)
@N Mamba: Upper :-)
Writing to output stream
Writing to output stream takes time in some languages so this is not our fault but its really disgusting on codechefs part. there could be some easy means to get output.
what is the limitation given?
what is the limitation given?
what is the given
what is the given limitation*?
The example is
The example is wrong!!!!!!!!!!!!!!!!!
Please explain me how come for i=1,j=0 the ans is 2. (iNDEX STARTS FROM ZERO)
part of inp is below -
..X.
XX.X
....
.XXX
ABOVE DATA REPRESENTS 2X2 OF GIVEN SAMPLE INPUT.
THE ANS IN THE ANSWER GRID AT I=1,J=0 SHOULD BE 1 not 2
cAN ANYONE PLZ EXPLAIN.................!!!!!!!!!!!!!!
You don't need to
You don't need to shout.
There are two Xs in a row horizontally starting from (1,0). Vertically or diagonally there is only 1, so the output is 2.
Hey Stephen.. I am not
Hey Stephen..
I am not shouting...
to print the part of the input I had caps on...and continued typing like that only....
Can u plz explain a bit...not getting correctly...
tx in adnavce..
There isn't much else one can
There isn't much else one can say; the X at (1,0) is part of a line of 2 Xs, so the answer is 2. The problem statement provides a more precise definition. If you don't understand part of the problem statement I can't guess which part you're not getting.
i am new here ...if i giv d
i am new here ...if i giv d test input i get the correct answer...but the submission is giving wrong answer ..wat shud i do..i hav cheked me code and its seems correct
If you get wrong answer then
If you get wrong answer then you have a mistake in your program. You won't be given any extra help as this is a contest.
in the output is der space
in the output is der space b/w the numbers
@ Aman - Output Output n
@ Aman -
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)
Stephen, Can u help me to
Stephen,
Can u help me to understand how we gon ans for below mentioned cells -
1. for i=9,j=2(last row 3rd column)
2. for i=9,j=3(last row 4rd column) and
3. for i=6,j=0(7th row, 1st column)
What i am doin is , I am counting number of continues X's around a cell..in all 8 directions.
plz help...
tx
You want to find a line of Xs
You want to find a line of Xs of maximal length going through the given point.
There are five Xs in a row horizontally going through (9,2) and (9,3), namely (9,2), (9,3), (9,4), (9,5), (9,6), so the answer to both is 5 (there is no longer vertical or diagonal line).
There are four Xs in a row diagonally going through (6,0), namely (6,0), (7,1), (8,2), (9,3), so the answer is 4 (there is longer longer vertical, horizontal, or other diagonal line).
@atul i agree
@atul i agree
hei Stephen Merriman this was
hei Stephen Merriman this was bad. please help...i dont know how to print a large array, in this question n=1000 want to print whole arrray hw it is posible to print B[1000][1000] in 2 sec;
actually i want to submit one ans. then i stop. am new in this type of programming. i think u help me;
please ans my question ..? or u comment why u deleting my question?
my email add is :
my email add is : e.rijin@gmail.com
Asking for help during a
Asking for help during a contest is not allowed; please stop posting lots of comments doing so. If you want to ask for help, wait until after the contest has finished.
Stephen, Thank you very much
Stephen,
Thank you very much for explaining....I am getting correct answer now..
ppl, the sample input/output is correct.
The problem i am facing is TLE, Same problem as RIJIN is facing..plz let us know if there is anything we need to follow to output 1000X1000
myid: sa.kul@rediff.com
ok..Stephen...will wait till
ok..Stephen...will wait till the end of contest...
meanwhile..will try from my end to solve...
tx
hei stephen am sorry; am not
hei stephen am sorry;
am not ask about the contest question, and hw is solved
1. in this question 2 sec is time right. is it is processing time or printing time? i write the program. work perfectly i think; but printing large array take more time?
@stephen i want clarification
@stephen i want clarification regardin d same thng as above
The time limit is 1.5
The time limit is 1.5 seconds, and that is the entire time from when your program starts to when your program finishes.
FAQ
@rjin
@rjin ...
http://www.codechef.com/wiki/faq#How_should_I_test_my_program
check this link ... They never try to display your input in their console. They redirect the output to a file . So printing input won't take much time I guess. You better try to optimise your code in some other way.
Hope this helps.
Please correct me if i'm wrong.
Thanks for your time..
In the actual input file,
In the actual input file, there seems to be some errant spaces. For example, there is a space after the number on the first line.
hello Stephen this is my
hello Stephen this is my first time here, i solved this problem but when i submit, it says runtime error, i use gcc and i tested my program with the test case given here and a few extra cases i thought relavant, and my program gives correct output for every case, i tested my program as instructed in the FAQ, and everything is alright from my side, i dint check time limit, but the thing that confuses me how can the code give runtime error while i am also using gcc same version? i got SIGSEGV i rechecked but there is no uninitialised variable, and i used dynamic allocation so there's no chance of large array,and i am freeing the memory after using,is there any specific way to know the exact error my program is throwing?
@Diptarag - no, you are not
@Diptarag - no, you are not able to find out any more information about the error. If you want someone else to help you with debugging your program, I am happy to do so after the contest has finished.
Hi, I'm getting exact(space
Hi,
I'm getting exact(space by space) output for your given input and is matching exactly with your given output.
I also ran my code for other inputs producing correct results that I checked by hand. But, while submitting it's giving wrong answer, can the admin check this problem or have a look if possible... :)
Thanks
Nothing is wrong with the
Nothing is wrong with the judge. Wrong answer means your answer is wrong.
i'm getting correct answer
i'm getting correct answer for various inputs
but on submission it says wrong answer
is it the problem of output format or anything else.
it's my first time!
anyone plese help.
thanks
I'm afraid you will not be
I'm afraid you will not be given help during the contest.
thanks for previous one. is
thanks for previous one.
is it x or X or it can be both.
The problem statement is very
The problem statement is very clear.
Hello admin: Do we have to
Hello admin:
Do we have to print a 'n' at the end of output, I mean.....
suppose n=5
2 0 2 0 1
4 3 3 0 0
0 4 0 3 0
3 0 4 0 3
0 3 0 4 2<STOP HERE or print one more newline character>
Thanks
hey there i am getting the
hey there i am getting the correct output but tim elimit exceeded
i checked my program for all
i checked my program for all cases of 3*3 matrix
it gives correct output and also for many other cases
on submission it says wrong answer
anyone plese help:)
it,s my first time
thanks
does input contains spaces
does input contains spaces
Stepehen- do we need to take
Stepehen- do we need to take care abt lower and upper case letters or it wud be in upper case only?
Come on people, the problem
Come on people, the problem statement is very clear as to what the input format is and to what the output format is. Does it say the input can contain a lowercase x? No. It says X. It means X.
my solution with
my solution with cin>>(string) was giving TLE, but with scanf("%s",char*) it got AC.
this is not gud...perhaps u should look into it..
in output is there a space at
in output is there a space at the end(after the last integer) ... and also is there a new line after that ??
also is there space after
also is there space after last integer of each line?... i think there is, right?
@Dal yeah there is..
@Dal
yeah there is..
for : i = 0 to n - 1 for : j
for : i = 0 to n - 1
for : j = 0 to n - 1
print : "%d " <- B[i][j]
end
print new line
end
will this give the given output format assuming B[][] is correct ??
please tell me wether my code
please tell me wether my code is generating wrong answer or it is format of output... ofcourse once the compition is over....
on submission it says code
on submission it says code run for 0.00 second but produce wrong results
if it runs it'll take atleast some time.
if anyone familiar with it plese help.
thanks
same here @ atul
same here @ atul
Can someone help with output
Can someone help with output from JAVA ?
Say I have the output prepared in StringBuilder sb
If I try to print it with System.out.println( sb) I get time limit exceeded error
also OutputStreamWriter doesn't work,
if I don't print the output I get wrong answer in time 0.24
I see there are 5 JAVA correct submissions, so there must be a way :)
although the execution times are terrible
any help (that doesn't violate the contest rules) will be appreciated
thanks
Any help does violate the
Any help does violate the contest rules :P Wait another day and a half for help.
Is there any way to see all
Is there any way to see all successful submissions for this problem so that I can see where I actually stand?
Thanks
@Stephen Merriman: thanks
@Stephen Merriman:
thanks anyway :) I translated the code into C++ and it passed with time 6.47, I believe one needs some better algorithm to pass with JAVA submission
hello everybody i have not
hello everybody i have not able to view the solutions
@Stephen or anyone who has
@Stephen or anyone who has solved this problem... can you help me to find out the prolem with my solution to the problem.. actually.. i feel.. i have designed a good algorithm.. but.. as it's not giving right solution.. so I want to find out were i missed out.. :)
Your latest submission
Your latest submission doesn't appear to be working on the sample input. Your four main functions aren't returning anything in the 'else' sections.
(PS - I advise you to never ever use getchar; it just isn't worth the hassle. Use scanf("%s".. to read in each row at a time instead.)
@Stephen how can I know why
@Stephen how can I know why my solution fail? I have compared my output with the output from successfully submissions and the results are the same. Please your help.
Have you allowed for the \\r
Have you allowed for the \r character that appears before \n in newlines? (See the FAQ.)
@Stephen.. Thankyou for your
@Stephen.. Thankyou for your reply... I corrected the else part.. and my solution is running fine for the sample input... though i haven't changed the getchar...
It may be running fine on
It may be running fine on your computer, but your computer can't be set up the same way as the judge. A new line on the judge contains two characters, \r and \n, as mentioned above and in the FAQ.