Dendrochronology
Statement
Goal
Determine the age of a tree by counting the number of rings in a horizontal cross-section of its trunk.You are presented with a 10×N grid representing a cross-section of a tree.
Every year, the tree alternates between a phase of rapid and slow growth depending on the season.
To compute the age of the tree, count the number of transitions between a cycle of rapid grow (line of 0), and slow growth (a line of 1).
A few considerations:
- There is an arbitrary number of lines per cycle.
- The tree trunk is not perfect and you must expect to see errors (i.e a 0 instead of 1 or vice-versa) or unwanted particles (represented by any other printable character).
- However, on any given line there will always be 10 characters, and less errors than valid characters.
Here is an example:
0000001000
1111111111
111111?111
0000000000
The age of this tree is 2 years since there are 2 transitions.
Input
Line 1: An integer N representing the height of the grid
Next N lines: Lines of 10 characters representing a section of the tree trunk
Next N lines: Lines of 10 characters representing a section of the tree trunk
Output
An integer representing the age of the tree
Constraints
0 < N ≤ 1000
Example
Input
2 0000000000 1111111111
Output
1
Game modes
Fastest, Shortest
Test cases
Simple case Test
Input
2
0000000000
1111111111
Output
1
Validator 1 Validator
Input
2
1111111111
0000000000
Output
1
Variable length Test
Input
5
0000000000
0000000000
0000000000
1111111111
1111111111
Output
1
Validator 2 Validator
Input
5
0000000000
0000000000
1111111111
1111111111
1111111111
Output
1
Errors Test
Input
8
1000000000
1000000000
1111111110
0111111111
1111000000
0000001111
1111111111
1000000000
Output
4
Validator 3 Validator
Input
8
1111000000
0000001111
1111111110
0111111111
0000000001
1000000000
1111111111
1111000000
Output
4
More Errors Test
Input
6
#000000000
000000000#
1101110111
00000!0000
0000000000
111111111#
Output
3
Validator 4 Validator
Input
8
L000000000
110000000L
1111111111
00000!0000
%000000000
1L1111111#
####000000
0000000!!!
Output
4
Very dirty trunk Test
Input
9
####000000
!0!0!0!000
1111111111
AZER111111
QWER111111
000000LKLZ
Y1Y1Y1Y111
1111000000
1111111111
Output
5
Validator 5 Validator
Input
9
1111111111
;;;;000000
WXYZ111111
ABCD111111
000000LYLY
N1N1N1N111
1111000000
1111111111
K0K0K0K000
Output
7
Very old tree Test
Input
603
*111111111
111*111111
21V11+1111
111116111Y
1111111111
100U0I0*01
1000&00001
1111SN1111
1111111111
11S1\11O1Q
000))#000D
00000,0P00
000000%000
1111211111
000000000E
0000000000
00000V0000
000000#002
111(#11),1
161111111#
1111,1111Z
11111111*1
1111111111
00H0500000
0I00804000
000UV000X0
0C0$0,0I00
1111111111
11191'1111
0000000&00
000000000&
O0000M00O0
Z1B11211-1
1111111111
1111000000
11!111W11R
1111-1N111
1111111111
1111111111
0000000000
0000000000
&00000A00/
Y000000000
1111!"1G11
1111>11111
1111111M11
0000000000
0000000000
00000C!000
11R1111111
111EL91111
91T1(11U11
1?11+11&11
00$000000#
000W000NV0
11?112&111
1111111111
Z11P11C'11
1;11111111
111.=11B11
0000[A1000
00*:0\X000
000\00"000
1[11111111
1N1111<191
0000000000
1111I-S1U1
111111)111
1111111111
1#11"111@1
000000000>
Q0;000Q00R
:Q11111%11
N111211H:1
W11M11:111
1-11X%111X
0Z0,,00$00
00OW000A0@
"000B0000V
0000000000
1L1111'111
B11;11:.11
111"11U1U'
("000000V,
0000000000
00000000/0
0000000000
L000000000
11111R11)[
11[01111=1
11110111ZQ
11&1111111
0000000000
1V1K111121
F11111=&41
111111X121
0220O00J00
1000000000
000T000000
00000000!0
000Y0100$0
114,11E1%1
000000A000
00C0000000
<00,W0000L
00000000K0
1(11511+1C
000!0000W0
0NK000000I
0000000000
0.00000)S0
1111111111
1Y11111111
111)11111S
0000000000
0000000000
500000+000
000+0X=00P
1111111111
1111Y11#31
N(1111Q311
0000-00K00
100L0L000J
11111111U1
+112111111
0000000000
0000000000
000000Y0D0
111111O111
11111C)111
1111111V11
0000%00000
,000000L0N
0Z00000000
0000000000
1111T11111
1111111111
00"0000000
008000\0##
0082005003
05L00N0000
1111111111
11@51111R1
1111111111
>!00000000
-00D00'0K0
00>0000000
11111#11Z9
000K;W000X
0000000S00
0000000000
11R1UZ111R
1111111111
00W0N00000
000[000000
000?0000A0
00000000X0
11!O111S11
1111=1K/11
11$1111111
000V000A00
0600000F&0
0000000000
0000G00000
000,000000
11B16U1111
11>!1111MT
1N11111101
111!111111
111G11111D
0B00000070
1111$11H11
51O1131111
0'Z(000000
000000000+
*0H0600'00
0000000000
1111111111
61111111A1
11U1111%11
1111111111
1111111111
0,00N0000>
0000\BE000
0!0000000G
)111611111
:11111A@1:
0000000000
0000D(00-0
008000$000
1/111K1BI1
111A111111
1N1111111W
0E000F000G
000000:)00
00\0900:00
0000000000
1111111T1!
1111011111
1F3181\111
11MP111>I1
0000000000
0400000<05
0000000000
11111?1111
11+114)111
11111E1111
1111111111
1!1/1I1111
0000000000
000&000000
11111111P1
111U111111
S00Z00000#
0000000000
0000000000
J11\1%11B1
S1(111V11%
111111H111
N0"U000000
0000000000
1711#1-11R
A11V1111[P
00E00,S000
0000T00000
0020008001
1111D*5111
0000000000
0000000000
Y9000)000+
11$11111V"
1[111<11'1
1E1111X1U>
1111=$1E[1
00000>0000
0000000000
?00300000)
0N02000900
300000/000
*111111111
1(G111111S
1151111111
1+11111111
$000"00000
05:00M0[00
N000000030
0000000000
0000000000
1111111Q11
111111[A.1
G1111L13$1
1111111?11
00000@0000
00Z00[0!#0
0000>00000
0000000020
L00000T000
1511111!11
11W1111F11
0000000000
0000000*00
0000000000
111:1N1111
1111'11111
111@111111
00%000!000
0000000000
0H'0000000
CN00000000
11#1111111
1111111112
1:Z161Z111
N1111111Z1
M11Z1C1111
0=09000000
60#00000&D
;111111111
0000000000
S0000;09/0
0S0<N00000
0:00:000DT
000000$00<
111111D111
040:0X0000
0U0DO00000
HU000000V0
1111111111
W00000/00@
0O00R0W00G
000A80!000
000000A00H
0700005000
1111111111
00E00.0000
11#1111111
0000000029
000000000/
Y0000003-0
000000*008
111111111L
111111G")1
1<111'11=1
0000000000
3A0000000#
0000000000
000%00I004
11111/1111
1111111111
1111111111
O1111T=11$
0@)0R00>00
00000000\0
0000000+Z0
000000T000
00000000(0
E113111*1V
111DQ111;#
/00000[000
00000Y0000
0000000000
1J%111S11V
111<191111
G1C1+E1111
1111111111
UD00000JY0
4000U0E00N
00000000B0
1:1111&\11
1111111211
11111111Z1
11:11111/1
00\0000M00
0000000000
000000000>
1111111111
115111-1O+
1111311111
11DL&%1111
0000000000
08000QR0.0
000"000000
0000000000
0070000P&M
1111111111
1111111116
0000000000
000V000F00
00000000.5
0000000000
0000000000
21(811,111
000000R+00
111N111111
11T1(11$11
1:11111J1B
1111\11111
1111<11"11
0000000000
1111%1(:11
1111111111
1111111S1Z
111*111111
[D1111)111
0>00000X0K
0000000000
00000000N0
!'0000;000
00B0000X00
1@1111M111
1111115111
T111111;11
11111:118(
1*11111111
0000<X00(0
\0W00(0P00
1111111111
6E?11111D1
1*>11$6111
111511X111
1111O"1111
000000ET./
0L\0000000
10711B1&11
<000002000
000&000000
0000000000
00U000Z00N
00%00$00;6
113?)11131
1181111111
1A1(11%111
11111!1111
X121211151
0000000000
0000000000
0000R@2000
00.0000000
00&00R(00E
1MN1111G12
0000100+0*
000K400%00
1111111611
11;+11+411
1141111111
111111.111
,1(1111111
V000000000
0000000@Q0
0000000000
0000000(00
1111-11111
B11,111UN1
1111111111
$0$100000&
006&000000
000%00>"0"
G0000000B0
1111:/1?11
WS111111.U
117,111111
11111/1111
0000000000
).0800%000
000C(0=000
11W@111111
1111111111
1*1111111I
IX1H11111=
1111131111
00(0?I0003
Z1F1111I21
1111111111
111H111111
(00Y0V0$00
0V00[0<500
00*00!D600
0000Y00$00
000000000I
/E11?1$111
0#0?000C00
00%20!0000
11111111C1
11WR11N1=1
11N11B111$
1"1111E1U1
11411111*1
0000000000
0LE0000&00
000FN00000
1P1111,11Y
M111113911
H11111JJ<1
05000M0000
L000200000
11H11/-111
11118112*1
-11111111"
11Y1=E111%
111FA111U\
0000000000
0000000400
000:000000
00U/00\K00
000000M0;0
111E111111
1.11111811
111N111111
000M0T000T
>Q00V00000
0000000000
07000F0&0:
000900000&
1I11N11E19
;1111111Z7
1111111111
1111711111
0C0000H000
0000000000
#O0000000<
1111111111
311131W111
1111111L11
151118111$
000000[000
00000000)0
0000000000
0000080.00
1M11B$1111
#111111111
1S21111711
07\0000000
D000004000
%0H00Z0#00
E11111+1UJ
P411111111
11K<111111
111K111111
1111111111
00>0000000
0(00000000
00000000\0
000K00L000
000&<00000
111X.11>"1
1111111111
1111SA1111
11W111111S
000000000.
1111111111
1117X1'111
00$8/00000
0000000000
11111111M4
11>11L;111
000000.M0%
000-0000W0
000004B0P0
0000000000
0000000000
1111111111
1111111111
0'000?00G0
0=00000000
0000000000
11111111E1
1171111111
11@K111111
111111111(
11I1111-11
V00000S)X0
0000P00000
1111111111
0000=0000E
0000000000
00Y00K000F
0@000000Q$
000)000000
1111111111
U0000C>0X0
000000000X
0T0000/"00
?000000000
1111111111
111111S1$1
000)00%008
511E11111'
111111-1(1
1T111,1311
000T40900B
0!0XO00S00
1111111111
1111111111
111114C1&?
11$11:11%1
:000000000
111111H1U1
1111M1111)
11"1L11LC1
1111111111
/0000::002
D1111111J1
11151=1011
1111111)11
T111111-11
1111111111
00L0000000
000P$DO000
0000000000
11111Y1C43
&1211Q11B1
111D11F111
1111111111
020+00;000
707000E0)0
0000X000:>
000#00000\
"1111WG611
%Q11111111
111L11111L
1111111111
0700E%F000
0000000S%%
00+000000>
0000000000
11111111W1
1#11111111
1182111+01
0000000000
000000I06P
0000070000
0000000000
1111P111D1
1AW18K1111
1111111111
1?11111111
08+0S0K000
000K000000
G000000000
000YJ00000
1)11111111
000000Y000
00000000O0
00B00000X0
Output
189
Validator 6 Validator
Input
602
0111111111
0000000$00
11111O1(11
300600[060
&9OD000000
"00O0000EW
000000U000
1111111111
1M111:11FQ
?00)0S0000
000000[0>0
0000!0E000
0:0S000000
C11'11[11O
1111111111
111/V111M2
0000000000
0000000000
0000000000
0200001.0)
11\1111111
1111111<11
1111000000
11H1111J+W
1@11311111
6111=11JO1
0(00>0$000
00000%0000
1N11111111
1111111111
000000000X
0IH0(000T0
[000000I09
1111111N1[
11$1111111
11111111Z1
111C0D111#
>,S111111.
S100000011
1111111111
1F@111:11T
11111111T1
11111111<1
0000000000
07O0B00000
00000<00G0
0080006000
0000000000
1?11[11111
5000000000
0000000000
0J00000000
11=1111111
11111<1111
11111JZ11I
1111111111
11M11Z1KM1
0000000000
0000000000
000#H)000Z
11111311,1
0000M?0000
0000000000
11111-1111
111111E111
11N1111111
11;7111"10
#1111X1111
0000000000
03K00H=000
11<L11[111
1111O11V1;
+)[111111!
000JI00#L0
0000000000
W0!0000400
000000000<
000000000/
1311111111
Z1[611111)
11111111Y1
1111111111
1S111\S171
0[00(000N0
0:00000000
1111111E1R
111W11M111
11=7111!1,
0000000000
0000400000
00'0000I:/
00@0000000
,111111,18
111157'111
1111111111
&111711811
@O1111*111
0C00000000
000Z000000
000800$$0;
0000000000
111%-*1111
R111111111
0000000000
00Z#00>000
$000K0$040
00A0000000
1111111111
111111111[
1T1111"11Y
0V00000000
0000000000
0;0L00040Q
0000000.00
11111B11:K
1111111111
1111111111
1+'11G1A11
11$111211M
0000000000
$00700080!
1111111"\1
0000000000
0000010000
00000M0JG!
1111[1''10
111-T11111
1111111111
11161:1UU1
1111111161
0000000000
S0000000/0
0000000000
Z0#0000=00
M111111111
11111%1111
0000000000
0000000004
0=000%00V0
1111111111
1111111111
1111111111
111111W111
1111111111
0000000000
00000#0000
000L0000ZM
1W1+11J111
1111111111
1111111111
111'118161
OX00000\Y0
0000+000A,
00E0000=00
000000!00,
K11=111111
115%111111
2111?1111L
1111"11111
1111R11111
0T>00800?0
V*80000000
1111111:M8
11111111V1
11111=111M
1>1J1.1211
1111111111
000000!0B0
11E51111,1
1111111111
111111111(
111Z1#Y111
0000000000
0709000"00
11$11=1111
11111111)$
1111111111
1111111111
11041111/1
000F000000
00K0000600
0000000Z00
116Y1L11/1
111111HD+1
11=1111P15
11=1(R1111
.!00000<00
11I1111111
1111W1=711
1111111111
11A1111+11
00;00<000S
000000+000
400+[0000A
0H00900000
0040000000
11111111H1
1111111111
B1111)@114
00000000)0
#20P000D00
00S0000IQ0
1111111111
111111(1K1
1111111111
0(0+0000.#
0000&0D090
0000000000
0000000000
1111>11111
1!1111111Q
1111111117
0000000000
0000000000
0000000000
0000000000
1111.211)1
0000009;0:
1;1Z1H#111
011Z111;11
1211J111U1
,1111IKV11
0000020000
0000000000
0[>000'000
0000000Z00
1";1111"1.
1111111111
111;1M11&Y
191112115G
1111111B11
0<C000-Q00
(00(0000O0
0000000000
08000#<:00
11.1"11111
2111111111
1111111111
0000000000
7111111111
1(1)111111
0060000000
0000000M0W
00000W00O0
0$@0D00000
0000E09000
Z11:111111
0000000000
1111111111
0[000'0070
EY0J00000!
00(0000000
00000<0000
000030000'
1115Z%1111
0000000000
0000000000
1)<11=111P
C1111111Y1
00000T0000
0-000!0000
0000000000
/00000300N
\00000000I
11M11V1Q17
111G1&1,A1
11W*111Z13
*P0000000K
0000000R00
<000000-00
%1114111\1
1111111111
000000000G
1111O#1111
111;141111
J>00000000
0000000000
0000000000
00$0W00E0D
00000P0Y00
1111F11?1!
00'0008V0E
000N0?0000
(0000G0000
0000@0000\
00[[00FG00
11"1-11Y11
Z111111311
0E*0&0D000
11111*11V1
1110111111
1R11""1111
0000000000
0000000Z00
0000000000
0000<00100
00Y0000S00
1P1111O111
%611((1111
1111111111
X11;111111
0000Z[90Q0
0900000000
11111F1111
000$0:0000
F0,0B000N0
050<00\00Q
11111111+=
1111111111
8J1111*111
1111111111
0000000000
0K700000)8
1111111111
1M1T111117
1111111111
0000000000
0#00000G00
11111!1111
1111111R11
11S1111N1Q
111H111111
000B00?000
000000-D00
0000000000
0\0\0000H0
0Z(00000&0
1111111111
1111(11111
1111111111
11U111111+
0U00*00(:0
0000000000
0000000000
11(.Q111+1
1<111111;1
11H1111111
1111111C11
08000000Y/
0'00007200
K111HW1111
1E1G111>11
4111111161
1111111111
0000000000
)0F0000000
0000000QV0
11111111X1
1111111111
000000W000
0000000000
000@000000
11H9111Z1)
1*11111111
0000000000
0000000000
111111\111
1111111111
1111111111
111L111111
G000P000-0
1111111111
1A1111111N
111*1S411D
111111=111
0000000000
008000I000
11T-11>11E
1N11111RC1
@1111111K1
1111111111
=11D11111J
0000000000
0000000000
0000D0.D/0
0000003000
11Z1111KH2
1111111111
1111G1L111
11111JU1=1
1T11911111
000AK00K0%
.11111;11:
111111+111
/000X+:000
0000000000
00000000V0
000V0000UI
0080000000
11J1111111
0000000000
00.S%00000
0>0000FG00
0000000000
11);1"11Y1
O111111111
X1L1111191
00E=000000
90000000W0
000=00000,
5?00000000
1111111111
>000000;00
000+00C003
020600N0G0
11115111Q1
1111W11+11
1211*>1141
0000000000
00C000-000
00%00I000J
11111>11Y1
+7/111111T
0000000000
0O000Z0$0=
0000000800
111111G1,1
1111111111
11111-11+1
0000000000
H000000GC0
0020000000
0000000000
07"=000000
/111111111
11111G1311
",000.F000
0000005(00
[<B11111=1
00L0000000
0000000000
I0000Z00:0
0-00<00S'0
11V1111111
1111111111
1111111.1P
005000;000
000$000000
0000000000
000000000P
1111111111
\111\)11U1
0L00000000
0@00&000Q0
00000"0000
0E0[0($000
0000000000
?11&111111
D>0G0D0000
0000(00J(0
-00'000000
1111111111
111&1111P1
Y00040+I00
1111111I11
1(11?1>11*
1F11:111>1
1111111111
0%00Y000W0
010$0/00(0
0000000000
111111'111
0&40000000
0000000000
0I00#0000N
S000000000
000000000Y
1111111!11
11111111A1
0000000000
811C111J11
+00H0*0000
O000000[0B
111A1T1111
000'0R&00J
0000000000
0-00000000
000%000000
111/1%[1V1
11NC1:1>11
1111W11111
1111111111
111111111G
0000Z00000
1111111111
1\11[11111
1111111111
R000000000
1111111111
11#1111111
11?1111111
1)11L11111
11T1111111
0000000300
0000000000
15111$1111
1+11111111
(111111111
1<1U1J1(11
0;000000T:
0009S00000
0000:000"0
VM0000000G
0000[+0+60
11W1111111
)11"WF1111
1M1D11?11[
0000&$0Y00
0000005000
11111111Q1
'1.C111111
111111111?
111\7W111B
1111111111
(0000#S005
0000000000
D000000000
00P0500010
1111111111
111111F1E1
1111Q111#M
1111111111
11T1YZ1111
0000000000
1111111$11
00Y0@00000
'0D0000H00
1111111111
1111AW11HO
11101.111\
000'0D00/0
000S0!00!1
000E00T00<
000;000000
Z111111111
000000000+
0000YPI000
F00RD0"000
1111111111
1M11181131
G111181$11
1111[11111
0000V00000
111;1X1111
000D000000
1$1"!111H1
(5000C0000
111D11111B
111611!<1O
11%1111&&0
1!#1111@>1
1V11111111
00B0000000
000000000%
A000M000T"
0000000000
:0(00>0000
1E115"D111
000L00000T
00000JU00W
00000000M0
0000000000
11=(1&11A1
111111111G
1111111111
0U00P0&000
00000,0A00
11%11W,111
00#&0N0000
0Z/000000:
0000000000
11111A1111
000H000000
Z0P000[0F0
0000000000
N+11111111
1>1111(1C1
1111111211
11111!1111
0000)0[008
0000000000
0000000000
0000000000
1111111111
1>111&;119
1141111.11
1'6+1K1111
0000000050
0S0*\00M00
01[000X0&0
000K00B000
1111113111
111/1#1111
N1111111F1
/E00P0000X
000.00:000
0040V30@00
0000000000
W00000000V
11<1R11111
1111111111
1111111111
Output
204
Trap Test
Input
12
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
Output
0
Validator 7 Validator
Input
16
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
Output
0
Solution language
Solution
Stub generator input