Signal Cascade
Statement
Goal
This puzzle is about chain reactions and propagation.Your task: You are given a grid containing numbers.
Each number represents the initial energy of a cell.
Every time a cell receives a signal, its energy increases by
If the energy becomes greater than
° Its energy resets to
° It sends the signal to all
If several cells overload simultaneously, they may be processed in any order and should give the same result.
Your task is to simulate the cascade until no more overloads occur and output the final grid.
Input
Line 1: Two space-separated integers H and W, the height and width of the grid.
Next H lines: Each line contains W digits (0–9) representing one row of the grid.
Next line: Two space-separated integers R and C, the row and column indexes (0-based) of the starting cell receiving the initial signal.
Next H lines: Each line contains W digits (0–9) representing one row of the grid.
Next line: Two space-separated integers R and C, the row and column indexes (0-based) of the starting cell receiving the initial signal.
Output
H lines: The final grid after the cascade.
Constraints
1 ≤ H, W ≤ 10
0 ≤ R < H
0 ≤ C < W
0 ≤ R < H
0 ≤ C < W
Example
Input
5 5 00000 08120 07930 06540 00000 2 2
Output
00000 09230 08040 07650 00000
Tags
Simulation, Grid
Difficulty
Easy
Test cases
Example Test
Input
5 5
00000
08120
07930
06540
00000
2 2
Output
00000
09230
08040
07650
00000
Example (Variation) Validator
Input
5 5
00000
04320
05910
06780
00000
2 2
Output
00000
05430
06020
07890
00000
Full Overload Test
Input
4 4
9999
9999
9999
9999
1 1
Output
0000
0000
0000
0000
Variation Full Overload Validator
Input
6 6
999999
999999
999999
999999
999999
999999
1 2
Output
000000
000000
000000
000000
000000
000000
Chain Reaction Test
Input
5 5
98989
89998
98989
89998
98989
2 2
Output
00000
00000
00000
00000
00000
Variation of Chain Reaction Validator
Input
4 4
9898
8998
9898
8998
3 2
Output
0000
0000
0000
0000
Diagonal Chain Test
Input
5 4
9090
0909
9090
0909
9090
0 2
Output
0302
3040
0403
3040
0302
Diagonal Chain (Variation) Validator
Input
5 4
9090
1909
9090
1909
9090
1 3
Output
0302
4040
0403
4040
0302
No Overload Test
Input
3 5
09009
34567
89012
0 0
Output
19009
34567
89012
Variation No Overload Validator
Input
3 5
09009
44567
99012
0 0
Output
19009
44567
99012
Large Calm Zone Test
Input
5 5
12345
67890
12345
67890
12345
4 4
Output
12345
67890
12345
67890
12346
Variation of the Large "Calm" Zone Validator
Input
5 5
12345
67890
12345
67890
11345
4 4
Output
12345
67890
12345
67890
11346
Random 1 Test
Input
8 8
56216539
28904942
76568587
24998868
63199871
03091281
12013239
13388564
5 3
Output
57327649
29038084
78900000
25000000
64500005
03205604
12124350
13388575
Random 1 (Variation) Validator
Input
8 8
10641459
25779568
77624688
08969999
04966991
42188859
44061161
33426767
4 6
Output
10652680
25780900
89969000
10000000
17000005
43400090
44184382
33426767
Random 2 Test
Input
10 10
4581127663
9799142986
9658750657
2982872404
9198961697
9025567179
5144016596
1082733427
1284893165
5929552222
4 2
Output
6904227663
0000452986
0000081657
6000003404
0600092697
0348777179
6244016596
1082733427
1284893165
5929552222
Random 2 (Variation) Validator
Input
10 10
9992141588
8318322342
9092643193
7959968768
0944961960
1038899284
9224590471
1789932648
5562208803
3152694957
7 4
Output
9992141588
9529322342
0405975293
0090000978
3089007070
2150000494
9249003571
1790063648
5574418803
3152694957
Solution language
Solution
Stub generator input