Discord

Checklist VsOSh AI 2026 Municipal Stage (Moscow), grades 9–11 · Task 6

Heat Map

Russian title: Тепловая карта

Find a minimum-area sub-rectangle of a colour grid that contains all k colours.

  • Algorithmic programming (two-dimensional search)
  • Russian original · English translation

The task

Slava's heat map is an n × m table of colours c_ij numbered 1 to k and is too large for his poster, so he wants to cut out a rectangular fragment that still contains at least one cell of every colour, with the smallest possible area. All k colours are guaranteed to occur.

Abridged and translated by SOTA from the official Russian materials. The official statement has the exact rules, and it wins wherever this summary differs.

In English

This task was published in Russian. SOTA translated its 4 files into English on 16 September 2026.

Read the task statement in English 568 words

Heat Map

English translation by SOTA – AI Community of the Russian original. Organisers who would like this translation removed can email [email protected].

Task 6 of the municipal stage (Moscow) of the All-Russian School Olympiad (VsOSh) 2025/26 in artificial intelligence, grades 9–11 (variant III). Original: tasks-ai-9-11-mun-msk-25-26.pdf.

Time limit: 1 second
Memory limit: 256 megabytes

Slava is preparing a poster for a conference. Unfortunately, his heat map does not fit on the poster at the moment: it is too large. So Slava decided to select some rectangular fragment of the current map and use it for the presentation. Slava's heat map looks like a table of nn rows and mm columns. The cell at the intersection of the ii-th row and the jj-th column has colour cijc_{ij}. There are kk colours in use, numbered from 1 to kk. An example of a similar map is shown on the right. Slava wants to show the whole range of values, so the selected fragment must contain at least one cell of each colour. At the same time, the young speaker wants to minimise the area of the map, because he needs to fit it on the poster.

[Figure: an example heat map, printed to the right of this text; see page 4 of the original PDF.]

Help him: find a rectangle that can be cut out of his map so that it contains cells of all kk colours. It is guaranteed that the original heat map contains cells of all kk colours.

Input format

The first line contains three natural numbers n,m,kn, m, k (1n,m2501 \leqslant n, m \leqslant 250, 1k201 \leqslant k \leqslant 20).
Each of the next nn lines contains mm natural numbers cijc_{ij} (1cijk1 \leqslant c_{ij} \leqslant k).

Output format

Output 4 numbers x1,y1,x2,y2x_1, y_1, x_2, y_2 that define the rectangle to be cut out. The rectangle is given by its top and bottom rows (x1x_1, x2x_2) and its left and right columns (y1y_1, y2y_2). If there are several ways to cut out a chart of the smallest area, output any of them.

Examples

Standard input:

3 4 3
1 1 2 2
3 1 1 3
1 2 2 2

Standard output:

1 3 2 4

Note

[Figure: see page 4 of the original PDF. Transcription: the 3×43 \times 4 map of the example, with three dashed outlines marking rows 2–3 × columns 1–2 (red), rows 1–2 × columns 3–4 (orange) and rows 2–3 × columns 3–4 (purple).]

column 1 column 2 column 3 column 4
row 1 1 1 2 2
row 2 3 1 1 3
row 3 1 2 2 2

All possible ways to cut out a chart of the smallest area for the first example.

Scoring criterion: exact match of the answer — 100 points

Maximum score for the task — 100

Translated by SOTA. The Russian original is the official version and wins wherever the two differ. Translated from the statement and answer PDFs of the Moscow municipal stage (grades 9–11) on vos.olimpiada.ru. The two figures are described in text (the example grid as a table), with links to the original pages. If you organise this olympiad and would like the translation removed, email [email protected] and we will take it down.

At a glance

You get
Standard input: n, m, k (1 ≤ n, m ≤ 250, 1 ≤ k ≤ 20), then n lines of m integers c_ij (1 ≤ c_ij ≤ k).
You submit
Four numbers x₁, y₁, x₂, y₂ (top and bottom rows, left and right columns) of any minimum-area rectangle.
Scoring
Checked answer; 100 points maximum.
Rules
  • Time limit 1 s; memory limit 256 MB.
Format
Municipal stage (Moscow), 17 December 2025, grades 9–11; individual; 180 minutes; answers and programs submitted to an online testing system; maximum 600 points for the paper.

Details

Year
2026, Moscow, Russia (in person)
Round
Municipal Stage (Moscow), grades 9–11 · Task 6
Language
Russian; English translation by SOTA
License
Not stated by the source