CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » July 2010 » Maximal crosses

Maximal crosses

Problem code: MAXCROSS

  • All Submissions

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


  • Submit

Comments

  • Login or Register to post a comment.

in the problem statement

shettynamit @ 1 Jul 2010 04:20 PM

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

rijin @ 1 Jul 2010 08:11 PM

which one of them are count for 'X' in 1,7?

Can somebody clarify the

Shoonya @ 1 Jul 2010 09:34 PM

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>?

mcsharma1990 @ 2 Jul 2010 01:16 AM

Is anti-digonal allowed>?

@Mahesh Chandra Sharma: both

anhdq_adm @ 2 Jul 2010 03:45 AM

@Mahesh Chandra Sharma: both two diagonal , and /, is ok ;-)

instead of writing our output

calc_saransh @ 2 Jul 2010 10:07 AM

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

dwrakh @ 2 Jul 2010 02:52 PM

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

shivmitra @ 2 Jul 2010 06:32 PM

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

shivmitra @ 2 Jul 2010 06:33 PM

read "n" as new line..sorry fr the mistake..

Can anybody plz explain the

Juned123 @ 2 Jul 2010 07:56 PM

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

triplem @ 3 Jul 2010 06:16 AM

@Everyone: Please constrain your comments to clarification requests. All other comments that have been completely unnecessary have been removed.

The diagonals are considered

rohitrulz @ 3 Jul 2010 09:33 AM

The diagonals are considered as one or as separate when calculating the maximum?

Separate, in the same way

triplem @ 3 Jul 2010 10:57 AM

Separate, in the same way that horizontal + vertical are separate.

this is bad.. i had to write

calc_saransh @ 3 Jul 2010 11:44 AM

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

bhathiya @ 3 Jul 2010 02:21 PM

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

N_Mamba @ 4 Jul 2010 01:53 PM

'X' should be in Ucase or Lcase ?!!

@N Mamba: Upper :-)

anhdq_adm @ 4 Jul 2010 08:26 PM

@N Mamba: Upper :-)

Writing to output stream

atullala @ 4 Jul 2010 11:25 PM

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?

tourniquet_grab @ 5 Jul 2010 12:50 AM

what is the limitation given?

what is the given

tourniquet_grab @ 5 Jul 2010 12:51 AM

what is the given limitation*?

The example is

sakul123 @ 5 Jul 2010 02:09 PM

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

triplem @ 5 Jul 2010 02:14 PM

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

sakul123 @ 5 Jul 2010 02:23 PM

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

triplem @ 5 Jul 2010 02:25 PM

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

wizgen @ 5 Jul 2010 02:29 PM

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

triplem @ 5 Jul 2010 02:46 PM

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

wizgen @ 5 Jul 2010 02:49 PM

in the output is der space b/w the numbers

@ Aman -   Output Output n

sakul123 @ 5 Jul 2010 02:54 PM

@ 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

sakul123 @ 5 Jul 2010 02:59 PM

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

triplem @ 5 Jul 2010 03:11 PM

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

N_Mamba @ 5 Jul 2010 04:33 PM

@atul i agree

hei Stephen Merriman this was

rijin @ 5 Jul 2010 04:34 PM

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 :

rijin @ 5 Jul 2010 04:41 PM

my email add is : e.rijin@gmail.com

Asking for help during a

triplem @ 5 Jul 2010 04:45 PM

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

sakul123 @ 5 Jul 2010 04:46 PM

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

sakul123 @ 5 Jul 2010 04:48 PM

ok..Stephen...will wait till the end of contest...

meanwhile..will try from my end to solve...

 

tx

hei stephen am sorry; am not

rijin @ 5 Jul 2010 04:59 PM

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

N_Mamba @ 5 Jul 2010 05:11 PM

@stephen i want clarification regardin d same thng as above

The time limit is 1.5

triplem @ 5 Jul 2010 05:34 PM

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

alengcm @ 5 Jul 2010 07:05 PM

@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,

ridiculousfish @ 5 Jul 2010 07:15 PM

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

Diptarag @ 5 Jul 2010 07:36 PM

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

triplem @ 6 Jul 2010 06:46 AM

@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

mtk @ 6 Jul 2010 11:30 AM

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

triplem @ 6 Jul 2010 11:38 AM

Nothing is wrong with the judge. Wrong answer means your answer is wrong.

i'm getting correct answer

v_new.c @ 6 Jul 2010 02:01 PM

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

triplem @ 6 Jul 2010 02:53 PM

I'm afraid you will not be given help during the contest.

thanks for previous one. is

v_new.c @ 6 Jul 2010 03:22 PM

thanks for previous one.

is it x or X or it can be both.

The problem statement is very

triplem @ 6 Jul 2010 03:26 PM

The problem statement is very clear.

Hello admin: Do we have to

mtk @ 6 Jul 2010 03:31 PM

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

jimmycool @ 6 Jul 2010 08:51 PM

hey there i am getting the correct output but tim elimit exceeded

i checked my program for all

v_new.c @ 6 Jul 2010 10:15 PM

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

v_new.c @ 7 Jul 2010 11:50 AM

does input contains spaces

Stepehen- do we need to take

arpitg1991 @ 7 Jul 2010 12:08 PM

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

triplem @ 7 Jul 2010 01:29 PM

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

aseem_pandey @ 7 Jul 2010 09:39 PM

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

Dalchand @ 7 Jul 2010 10:03 PM

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

Dalchand @ 7 Jul 2010 10:06 PM

also is there space after last integer of each line?... i think there is, right?

@Dal yeah there is..

aseem_pandey @ 7 Jul 2010 10:33 PM

@Dal

yeah there is..

for : i = 0 to n - 1 for : j

Dalchand @ 8 Jul 2010 04:38 PM

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

Dalchand @ 8 Jul 2010 08:39 PM

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

v_new.c @ 9 Jul 2010 01:04 AM

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

Dalchand @ 9 Jul 2010 06:00 PM

same here @ atul

Can someone help with output

bohuss @ 10 Jul 2010 03:18 AM

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

triplem @ 10 Jul 2010 04:34 AM

Any help does violate the contest rules :P Wait another day and a half for help.

Is there any way to see all

ravigupta @ 10 Jul 2010 11:18 AM

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

bohuss @ 10 Jul 2010 12:53 PM

@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

jimmycool @ 11 Jul 2010 08:09 PM

hello everybody i have not able to view the solutions

@Stephen or anyone who has

linuxfreak @ 12 Jul 2010 08:37 PM

@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

triplem @ 13 Jul 2010 07:15 AM

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

jc_ortz @ 16 Jul 2010 07:26 AM

@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

triplem @ 16 Jul 2010 11:00 AM

Have you allowed for the \r character that appears before \n in newlines? (See the FAQ.)

@Stephen.. Thankyou for your

linuxfreak @ 19 Jul 2010 08:10 AM

@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

triplem @ 19 Jul 2010 10:57 AM

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.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com