ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1287. Mars Canals

Hint: be simple
Posted by ASK 31 Mar 2010 19:13
Make a macro for "for"

#define F(i,n) for(int i = 0; i < n; ++i)

macros for start/process/stop of each line
 #define START int c0 = 0, ...
 #define P(x) if(x == 's'){ ...
 #define STOP mc0 = max(mc0, c0); ...

vertical/horizontal lines are simple:
  F(i,n){ START; F(j,n) P(s[i][j]); STOP; }
  F(i,n){ START; F(j,n) P(s[j][i]); STOP; }

The simplest diagonal is
  F(i,n)  { START; F(j,i+1) P(s[  i-j ][  j ]); STOP; }

with a macro for symmetry
#define I(ind) n-1-(ind)

the other lines simply invert some of coordinates:
  F(i,n)  { START; F(j,i+1) P(s[I(i-j)][  j ]); STOP; }
  F(i,n-1){ START; F(j,i+1) P(s[  i-j ][I(j)]); STOP; }
  F(i,n-1){ START; F(j,i+1) P(s[I(i-j)][I(j)]); STOP; }