No More Pythons, Please!
Statement
Goal
Given an ASCII drawing of NxM characters. You must output the longest snake size in the image. It is also necessary to output the number of snakes with such size.On the field "
The snake is depicted by the following constant symbols:
"
"
"
"
..*-o
..|..
*-*..
|....
v....
It is guaranteed that it's possible to unambiguously determine which symbol refers to which snake:
The second character from the head and from the tail cannot be a "
Also, one snake cannot have two "
Input
Line 1: Two space-separated integers N and M for the height and the width of the figure.
Next N lines: The M characters which can only beo , | , - , * , < , v , ^ , > , or . .
Next N lines: The M characters which can only be
Output
Line 1 : The size of the largest snake in the input figure.
Line 2 : Count of snakes with the largest size.
Line 2 : Count of snakes with the largest size.
Constraints
5 ≤ N ≤ 80
5 ≤ M ≤ 80
5 ≤ M ≤ 80
Example
Input
7 7 ....... ....... ....... <-----o ....... ....... .......
Output
7 1
Tags
Ascii Art, Loops, Conditions, 2D array, Strings
Difficulty
Easy
Test cases
Easy (One Snake) Test
Input
7 7
.......
.......
.......
<-----o
.......
.......
.......
Output
7
1
Validator Easy-One (One Snake) Validator
Input
7 7
.......
...o...
...|...
...|...
...|...
...v...
.......
Output
5
1
Medium 1 (3 Snakes, One Pattern) Test
Input
5 7
*-----*
|*---*|
||*-*||
|||.|||
vov.ovo
Output
15
1
Validator Medium 1 (3 Snakes, One Pattern) Validator
Input
5 11
*---------*
|.*-----*.|
|.|.*-*.|.|
|.|.|.|.|.|
v.o.v.o.v.o
Output
19
1
Medium 2 (More than 1 large snake) Test
Input
6 10
^o^o^o^o^o
||||||||||
||||||||||
||||||||||
||||||||||
ovovovovov
Output
6
10
Validator Medium 2 (More than 1 large snake) Validator
Input
11 10
<--------o
..........
o-------->
..........
<--------o
..........
o-------->
..........
<--------o
..........
o-------->
Output
10
6
Hard (One VERY large snake) Test
Input
16 16
*--------------*
|*------------*|
||*----------*||
|||*--------*|||
||||*------*||||
|||||*----*|||||
||||||*--*||||||
|||||||o.|||||||
||||||||.|||||||
|||||||*-*||||||
||||||*---*|||||
|||||*-----*||||
||||*-------*|||
|||*---------*||
||*-----------*|
v*-------------*
Output
254
1
Validator Hard (One VERY large snake) Validator
Input
64 64
*-------------------------------------------------------------*o
|*-----------------------------------------------------------*||
||*---------------------------------------------------------*|||
|||*-------------------------------------------------------*||||
||||*-----------------------------------------------------*|||||
|||||*---------------------------------------------------*||||||
||||||*-------------------------------------------------*|||||||
|||||||*-----------------------------------------------*||||||||
||||||||*---------------------------------------------*|||||||||
|||||||||*-------------------------------------------*||||||||||
||||||||||*-----------------------------------------*|||||||||||
|||||||||||*---------------------------------------*||||||||||||
||||||||||||*-------------------------------------*|||||||||||||
|||||||||||||*-----------------------------------*||||||||||||||
||||||||||||||*---------------------------------*|||||||||||||||
|||||||||||||||*-------------------------------*||||||||||||||||
||||||||||||||||*-----------------------------*|||||||||||||||||
|||||||||||||||||*---------------------------*||||||||||||||||||
||||||||||||||||||*-------------------------*|||||||||||||||||||
|||||||||||||||||||*-----------------------*||||||||||||||||||||
||||||||||||||||||||*---------------------*|||||||||||||||||||||
|||||||||||||||||||||*-------------------*||||||||||||||||||||||
||||||||||||||||||||||*-----------------*|||||||||||||||||||||||
|||||||||||||||||||||||*---------------*||||||||||||||||||||||||
||||||||||||||||||||||||*-------------*|||||||||||||||||||||||||
|||||||||||||||||||||||||*-----------*||||||||||||||||||||||||||
||||||||||||||||||||||||||*---------*|||||||||||||||||||||||||||
|||||||||||||||||||||||||||*-------*||||||||||||||||||||||||||||
||||||||||||||||||||||||||||*-----*|||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||*---*||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||*-*|||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||.||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||.v|||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||*--*||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||*----*|||||||||||||||||||||||||||||
||||||||||||||||||||||||||||*------*||||||||||||||||||||||||||||
|||||||||||||||||||||||||||*--------*|||||||||||||||||||||||||||
||||||||||||||||||||||||||*----------*||||||||||||||||||||||||||
|||||||||||||||||||||||||*------------*|||||||||||||||||||||||||
||||||||||||||||||||||||*--------------*||||||||||||||||||||||||
|||||||||||||||||||||||*----------------*|||||||||||||||||||||||
||||||||||||||||||||||*------------------*||||||||||||||||||||||
|||||||||||||||||||||*--------------------*|||||||||||||||||||||
||||||||||||||||||||*----------------------*||||||||||||||||||||
|||||||||||||||||||*------------------------*|||||||||||||||||||
||||||||||||||||||*--------------------------*||||||||||||||||||
|||||||||||||||||*----------------------------*|||||||||||||||||
||||||||||||||||*------------------------------*||||||||||||||||
|||||||||||||||*--------------------------------*|||||||||||||||
||||||||||||||*----------------------------------*||||||||||||||
|||||||||||||*------------------------------------*|||||||||||||
||||||||||||*--------------------------------------*||||||||||||
|||||||||||*----------------------------------------*|||||||||||
||||||||||*------------------------------------------*||||||||||
|||||||||*--------------------------------------------*|||||||||
||||||||*----------------------------------------------*||||||||
|||||||*------------------------------------------------*|||||||
||||||*--------------------------------------------------*||||||
|||||*----------------------------------------------------*|||||
||||*------------------------------------------------------*||||
|||*--------------------------------------------------------*|||
||*----------------------------------------------------------*||
|*------------------------------------------------------------*|
*--------------------------------------------------------------*
Output
4094
1
Snake Madness (for Geeks) Test
Input
80 80
................................................................................
................................................................................
...o....................................................o.......................
...|....................................................|.......................
...|....................................................|.......................
...|....................................................|.......................
...|.................o->................................|.......................
...|....................................................|.......................
...*----->..............................................|.......................
........................................................|.......................
........................................................|.......................
.................................................o----->|.......................
........................................................v.......................
................................................................................
................................................................................
o-----------------------------------*...........................................
............................o------*|...........................................
......................^............||...........................................
......................|............||...........................................
....................o-*............||...........................................
...................................||...........................................
...................................||...........................................
...................................||...........................................
...................................||...........................................
...................................||...........................................
...................................||...........................................
...................................v|...........................................
....................................|...........................................
....................................|............................^^^^^^.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|.................*-----*....||||||.........
....................................|.................|*---*|....||||||.........
....................................|.................||o..||....||||||.........
....................................|.................|||..||....||||||.........
....................................|.................v|*--*|....||||||.........
....................................|..................*----*....||||||.........
....................................|............................||||||.........
....................................|............................||||||.........
....................................|............................o|||||.........
................<-----------------o.|.............................|||||.........
....................................|.............................|||||.........
..................................o.|.............................|||||.........
^.................................|.|.............................||o||.........
|.................................|.|.............................||.||.........
|.................................|.|.*------------*..............||.||.........
|.................................|.|.|*---------->|..............||.||.........
|..........o--------------------->|.|.||...........|..............||.||.........
|....o--------------------------->|.|.||...........|..............||.||.........
|..o----------------------------->|.|.||...........|..............o|.||.........
*--------------------------------o|.|.||...........|...............|.||.........
..................................|.|.||...........|...............|.||.........
..................................|.|.||...........|...............|.||.........
..................................|.|.||...........|...............|.||.........
..................................|.|.||...........|...............|.||.........
..................................|.|.v|...........|...............|.o|.........
..................................|.*--*...........|...............|..|.........
..................................*----------------*...............o..|.........
.............................................................o--------*.........
Output
123
1
Validator Snake REAL Madness Validator
Input
80 80
*---------------------------------*o*---oo<------------------------------------o
|<-------*o----------------------*|||<--*|ooooooooooooooooooooooooooo*----o<--*^
o^^^^^^^^|<-------**------------*||||o->||||||||||||||||||||||||||||||*---*oo^||
o||||||||*-------*||o----------*||||*---*||||||||||||||||||||||||||||||o->||||||
||||||||*-------o||*---------*^|||||o<--o||||||||||||||||||||||||||||||<--*|||||
|||||||*--------o|*--o<-----*||||||||o--*|||||||||||||||||||||||||||||*---ovv|||
vooooo*---------o*---------*|||v||||*--*||||||||||||||||||||||||||||||o------*||
<-------------------------o|||*-*|||*->||||vvvvvvvvvvvvvvvvvvvvvvvvvv*--------*|
<-------------------------o||*--ov|||..||||o-----------------------------------*
<-------------------------o|*-----*v*-ovv||<-----------------------------------o
<-------------------------o|<-----------o||o----------------------------------->
<-------------------------o*-------------*v<-----------------------------------o
o----------------------------------->^*-------------*o------------------------->
<-----------------------------------o||o----------->|o------------------------->
o----------------------------------->||^^o-*^*-----*|o------------------------->
*-----------------------------------o||||..|||^o--*||o------------------------->
|*--------*^^^^^^^^^^^^^^^^^^^^^^^^^^||||<-*|||*-*|||o------------------------->
||*------o||||||||||||||||||||||||||||||*--*||||^|||*---------*o---------*ooooo^
|||^^o---*|||||||||||||||||||||||||||||*--o||||||||*----->o--*|o--------*|||||||
|||||*-->||||||||||||||||||||||||||||||o-->o|||||v*---------*||o-------*||||||||
||||||<-o||||||||||||||||||||||||||||||*---*||||*----------o||*-------*||||||||o
||voo*---*||||||||||||||||||||||||||||||<-o||||*------------**------->|vvvvvvvvo
v*-->o----*ooooooooooooooooooooooooooo|*-->|||*----------------------o*------->|
o------------------------------------>oo---*o*---------------------------------*
<-------------------------o*-------------*^<-----------------------------------o
<-------------------------o|<-----------o||o----------------------------------->
<-------------------------o|*-----*^*-o^^||<-----------------------------------o
<-------------------------o||*--o^|||..||||o-----------------------------------*
<-------------------------o|||*-*|||*->||||^^^^^^^^^^^^^^^^^^^^^^^^^^*--------*|
^ooooo*---------o*---------*|||^||||*--*||||||||||||||||||||||||||||||o------*||
|||||||*--------o|*--o<-----*||||||||o--*|||||||||||||||||||||||||||||*---o^^|||
||||||||*-------o||*---------*v|||||o<--o||||||||||||||||||||||||||||||<--*|||||
o||||||||*-------*||o----------*||||*---*||||||||||||||||||||||||||||||o->||||||
ovvvvvvvv|<-------**------------*||||o->||||||||||||||||||||||||||||||*---*oov||
|<-------*o----------------------*|||<--*|ooooooooooooooooooooooooooo*----o<--*v
*---------------------------------*o*---oo<------------------------------------o
o------------------------------------>oo---*o*---------------------------------*
^*-->o----*ooooooooooooooooooooooooooo|*-->|||*----------------------o*------->|
||^oo*---*||||||||||||||||||||||||||||||<-o||||*------------**------->|^^^^^^^^o
||||||<-o||||||||||||||||||||||||||||||*---*||||*----------o||*-------*||||||||o
|||||*-->||||||||||||||||||||||||||||||o-->o|||||^*---------*||o-------*||||||||
|||vvo---*|||||||||||||||||||||||||||||*--o||||||||*----->o--*|o--------*|||||||
||*------o||||||||||||||||||||||||||||||*--*||||v|||*---------*o---------*ooooov
|*--------*vvvvvvvvvvvvvvvvvvvvvvvvvv||||<-*|||*-*|||o------------------------->
*-----------------------------------o||||..|||vo--*||o------------------------->
o----------------------------------->||vvo-*v*-----*|o------------------------->
<-----------------------------------o||o----------->|o------------------------->
o----------------------------------->v*-------------*o------------------------->
^o^o^o^o^o^o^o^o^o<------------------------------------------------------------o
||||||||||||||||||<------------------------------------------------------------o
ovovovovovovovovovo--------------------------------------------------------->o^o
o------------------------------------------------------------><-------------o|||
<--------------oo----------------------------------------------------------->vov
o------------------------------------------------------------>o^o^o^o^o^o^o^o^o^
o^oo--------------------------------------------------------->||||||||||||||||||
|||<---------------------------------------------------------ovovovovovovovovovo
|||o-------------><------------------------------------------------------------o
|||<-----------------------------------------------------------oo-------------->
vov<-----------------------------------------------------------oo-------------->
o->o------------------------------------------------------------><-------------o
o-------------------------------------->o------>o------>o------>o------>o------>
<----o<--o<----o<----o<----o<----o<----o<--------------------------------------o
<----o<--o<----o<----o<----o<----o<----o<--------------------------------------o
o-------------------------------------->o------>o------>o------>o------>o------>
o->o------------------------------------------------------------><-------------o
^o^<-----------------------------------------------------------oo-------------->
|||<-----------------------------------------------------------oo-------------->
|||o-------------><------------------------------------------------------------o
|||<---------------------------------------------------------o^o^o^o^o^o^o^o^o^o
ovoo--------------------------------------------------------->||||||||||||||||||
o------------------------------------------------------------>ovovovovovovovovov
o-------------------------------------->o---->o---->o---->o---->o---->o-->o---->
<------o<------o<------o<------o<------o<--------------------------------------o
o-------------><------------------------------------------------------------o<-o
<--------------oo----------------------------------------------------------->^o^
<--------------oo----------------------------------------------------------->|||
o------------------------------------------------------------><-------------o|||
o^o^o^o^o^o^o^o^o^o--------------------------------------------------------->|||
||||||||||||||||||<---------------------------------------------------------oovo
vovovovovovovovovo<------------------------------------------------------------o
Output
62
20
Solution language
Solution
Stub generator input