← November 2025 questions

NOVEMBER 2025 / ADVANCED / QUESTION 3

Question 3

Archived question

Try the question in your own editor, then check your output below.

THE QUESTION

Text from the official booklet. Refer to the PDF for original mathematical notation, formatting, and linked input files. Printed samples and inputs are reproduced as published.

You are exploring a rectangular robot base arranged in an N × M grid. Each cell
contains a tile that emits energy when stepped on. You start at cell S, and your goal
is to reach cell T . Each step increases the energy cost, depending on the difference in
energy intensity between the current cell and the next one. You must escape using as
little energy as possible to avoid detection.
Each cell contains:
• ’0’ to ’9’ → energy intensity (0 = inert, 9 = strongest)
• Walls ’#’ → blocked cells
• S → Start cell
• T → Target cell
• ’.’ → empty cell with energy intensity 0
Movement Cost Calculation: If you move from cell ( x1, y1) with energy A to cell
(x2, y2) with energy B:
cost = 1 + |A − B|2
Examples:
• From 3 → 3: cost = 1 + |3 − 3|2 = 1
• From 2 → 8: cost = 1 + |2 − 8|2 = 37
• From . → 7: cost = 1 + |0 − 7|2 = 50 (’.’ = energy 0)
Input format:
• First line: N M (1 ≤ N, M≤ 2000)
• Next N lines: grid rows of M columns
Output format: A single integer → minimum cost
Sample Input:
5 7
1..3..2
..#..#.
S23..4T
.#....#
9..8..7
Sample Output:
32
Input
40 80
30#.879.3390#.31844#.6##060..0038.15#97#0.7#.6#2#..#75#.#.89521234.64..#0#..88#.
77#.#9.57##1#1.#34#6#1.#36#.0##7#182870#91.507.#4516#.#.987#4979##06.4749#.3#033
8967#81.#9#81#8..7##.2#.#..39.##70.04.#8####.#27##8154#.#.287##62190##24#.5##716
428###33755#357#..8#1.#.##.9#20.9...#744..4.792##7#74749..53#095.73###9.4#533291
#3.2#.8.27####3#.8.4#4#.2#0#4##35#714182906837##438.#494.#35#283.##.#7#.###.5#.5
694##36103T289932825424612851409727#.#####2.0#.5#9...1#3#778971##8##.##7#169101#
02#7#85##566..9.710#.6#.###..#7##816#7.###25####5..#51482.##.54#7#3#75#.#610####
##9#.4.438.#7##..1991##851#..#016##6935#2.5588#619#9#3#159#8#9##7.1937..#2.#69#4
.#.4.0304#6##3#42#.907#2#5.#959###85#8#541#22.9#1..4#.9.#9##3#8#0#725..0#02#425.
402##68..8##2##98#5##.#17#91.11#.#.745##2151#.#694##38#10#3#8#84##0131##.3##7#7#
.884..35.9##1##1#0834.#7..#438#.###8#80937.62#3.2#.3#.#935#6.6#3460.55527#5#818#
.0.98.9.4441#7###8#1.1602##1#8#6###.##9##4285810##294.10.6483.7#270100#0#.....2#
1427#320#6#4..3.#.####458#43#7##.##5.14..48#920#663.3#2.37#0#282.9196417.6###5..
75.###89..3#5##..##8.9.#.199#0#2##1##2.#.1791.57..##.3220174.4#8###.9##.7######5
6#8793##7.91.2#######701.420###067.7#.#97#225.65178#92..#067268.8.3#2#1.##53.8##
516.5#86#9#9#..9#0#328#.76#1.##55.0.#8868#4#274#89.#.1#.##9.6#.9940#1.5##6.5#..3
319040159.3#.087196863.#3572##3###2.6#4.#.####95#.6.0##92.1#70284#8###537#29687#
#597##.3##538#93####1.##1.04#78####.#6#####76448#.#1.#685..#2.#9.0#1##99.6##6154
.0#3#883.####094##7233#49##9#6##2...536#1##60#70###032#.#####..52#..####222###.3
1.1#2#07#.54.#68714..##392.#7.5#3.76#625#017.#17696#69##.516920#62#.06.2#0#.#4#2
###8##5.#..#42.#1289#883#####2#502373##56#422#..83.#.###6936#5.5377#.292#760#9.#
4#.#.#1##.#6#05#53.#.5#.0##.#765#3.13#.#0###5###361##678.0##7.##.#3##20.6#14#...
####98###71#229.8#1..96###5##.29626#8#7444.##4###164#.#..36#8#0#28349##8.###2#84
968#2.##9#.#####7##62#..#4#145###1#7###8..9#.#.##.#39#8.#..92218#97#.#93.#######
##9##4#.23..2##.2#.7#8##573#24#..22####428..5392.914#.822#96#300#.4#88#851.#32.3
168.16.0#89#7#46#.#25###8#.5.7#1#74#7530##63#64#8##9.#71860.6..593.#0.#2.082#9##
##27#74#70#..732007##25582###0#.315.7##24#.077..#.#56####12###.3#.3.##7.3#.930.3
.#4..#8#8#92...###.546##6#4...#2#.##3.4.9#####.544#817#27#.#0.1###1#6#4#085##.03
4..#9#7##33.36#65##2.9#7..5#.#526#.#.3.##83#.9#7#6.3879##7...3#90#.506.7##68##.0
#030#5#58481#9349102#22#3465772##5#173#1516##66#601###95.###5#08.####958.#.9#08#
92#.979#0#7...#.67##085418.#36#.4#65.##209.656#8.#0.4124##3..6.8#006327#..6.#6##
9...#0.9.3#1498594615.#4.97#0#28###8..#9##3#8.1.#.6057981398054#2.##8.93#0..1#.#
##514.#.6722.927#.7#.7##4##9#####8#7..#.478#62.33420..#11#32.#..5.#.797164##..##
#.##7#2#6.8##6#9928#3##37.3#414802.1#5722##644#10.0#9..#2.2292#4#4..541#..09##58
#41.##10#1..2#5##44#..2#7.0##8#.###8#8#..03##4.8#6.#.6#7#45616936630746.09.8.7.#
#9.5#.8#38..##48#6#.01#7##4..4#821.#0#.6#5###36198#.9.#0##6...##.8#6#766###3.#7#
#0#3#231396.#..7#.3#2.#2#.9#011918739##5#5..0#7.40##0.#98.##3#61#7#.#363..0#2#.5
22#1#98##..473181#213#8#.33#6....#50.#170603#5....##252369.12616##.4#082S86###82
83..711..7612#2.7529#2.#15.6#940#207.125##.1##.#8###37.1##9056#.89.679.883.##.0#
1##3.71.4#7526###..450###98#.5#6.51###8#6#2377###.#0##6710.###6#019#..858#.##1#7

PRACTICE CHECK

Try your answer.

Practice convention: S and T have energy 0 and moves are up/down/left/right. The published sample output conflicts with that convention; this check uses the stated cost formula on the full final grid.

Run your program in your own editor, then paste its output below. This checks the stated output or checkpoint; it does not assess your full program. Practice attempts do not affect competition scores.

Use the question input above. Enter only the output.

Reveal worked answer

Your output

1208

Use Dijkstra’s algorithm on orthogonal non-wall neighbours with cost 1+(A−B)². Start and target cells have energy 0 for this check; return −1 if unreachable.

Source: Girls in Code SEA 2025 Fall Competition, 29 November 2025. Booklet created by Emily Xu and the GIC question authors. Shared for non-commercial educational use with attribution, as permitted in the booklet.