
2025 · Task 1
The Great Christmas Elf Photo
Santa wants to take a Christmas photo as a keepsake. Every single elf is in the picture - 1000 of them, to be precise - lined up in 10 rows of 100 elves each. The dear old fellow is terribly sentimental and wants to hold on to every precious moment, so a photo like this is just the thing.
The elves are very sociable, but also rather sensitive. Every elf has an opinion of every other elf. Some adore each other (100), while others can't stand each other at all (0). In short, an elf's opinion of another elf is on a scale of [0, 100].
Your task is to arrange the elves in a 10×100 panorama so that they are as happy as possible with their nearest neighbours.
Input
- 1000 lines, where each line represents one elf's opinions of all the other elves
- Each line has exactly 1000 integers from 0 to 100, separated by commas (no spaces)
- The number at position (i, j) = how much the i-th elf likes the j-th elf
- The diagonal is always - (an elf has no opinion of itself)
- The matrix is not necessarily symmetric (the i-th elf may love the j-th elf (100) while the j-th elf doesn't like the i-th at all (0))
Output
A single line with exactly 1000 numbers from 1 to 1000, separated by commas (no spaces and no trailing newline). Every elf can and must appear exactly once, i.e. every number from 1 to 1000 must appear exactly once. The first 100 numbers in the line represent the first row of the photo, the next 100 numbers represent the second row of the photo, and so on.
Example output: 542,883,121,76,997,234,567,890,12,445,378,255,901,666,123,...,999
Scoring
Scoring consists of two parts:
- Total happiness
- Minimum happiness
The score range is [0, 100 000].
Total score = Total happiness + Minimum happiness
Total happiness (80% of the points)
Each elf only looks at its orthogonal neighbours (up, down, left, right):
Happiness of an elf = sum of its happiness towards all of its orthogonal neighbours
Total happiness = sum of the happiness of all elves
Theoretical maximum: 378 000 (all neighbours 100)
Theoretical minimum: 0 (all neighbours 0)
Points = ( your_total_happiness ) / 378 000 × 80 000
-> if every elf hates all of its neighbours (all neighbours 0) = 0 points for this part
-> if every elf adores all of its neighbours (all neighbours 100) = 80 000 points for this part
Minimum happiness (20% of the points)
Minimum happiness of an elf = the lowest happiness towards any of its orthogonal neighbours
Minimum happiness = the lowest happiness of any elf towards its orthogonal neighbours in the photo
Theoretical maximum: 100 (all neighbours 100)
Theoretical minimum: 0
Points = (your_minimum_happiness) / 100 × 20 000
-> if there is an elf with a neighbour it hates (one of its neighbours has a liking of 0) = 0 points for this part
-> if every elf adores all of its neighbours (all neighbours 100) = 20 000 points for this part
Example
This is a simplified example with 9 elves: a photo with 3 rows of 3 elves.
Input
-,39,80,24,76,45,33,32,53
0,-,73,51,67,57,41,57,43
33,53,-,77,75,40,76,46,18
33,55,62,-,53,41,22,37,65
58,26,51,37,-,64,63,30,47
50,43,48,64,87,-,57,55,29
67,41,23,32,52,43,-,58,40
84,67,53,29,26,23,53,-,4
74,77,58,54,61,28,38,87,-
Output
5,2,6,3,1,7,8,4,9
This translates to:
- Row 1: 5 2 6
- Row 2: 3 1 7
- Row 3: 8 4 9
Elf 5 is in the top-left corner. Its neighbours are elf 2 to the right and elf 3 below. Its happiness is the sum of how much it likes elf 2 and how much it likes elf 3. In the matrix, these are the numbers at positions (5,2) and (5,3), i.e. 26 and 51. Elf 5's happiness is 26 + 51 = 77. Its minimum happiness towards its neighbours is the smaller of these two numbers, i.e. 26.
For elf 2, top centre, the neighbours are elf 5 to the left, elf 6 to the right and elf 1 below. Its happiness is the sum of the numbers (2,5), (2,6) and (2,1), i.e. 67 + 57 + 0 = 124. Its minimum happiness towards its neighbours is the smallest of these three numbers, here 0.
Elf 1 is in the centre of the photo. Its neighbours are elf 2 above, elf 4 below, elf 3 to the left and elf 7 to the right. Its happiness is the sum of the numbers (1,2), (1,4), (1,3) and (1,7), i.e. 39 + 24 + 80 + 33 = 176. Its minimum happiness towards its neighbours is the smallest of these four numbers, in this case 24.
The happiness of the remaining elves is calculated in the same way. The total happiness of the photo is the sum of the happiness of all elves. The minimum happiness of the photo is the lowest minimum happiness among all elves - in other words, take the elf that is least happy with its neighbours, and its value defines the minimum happiness of the whole photo. In this example, the total happiness is 1090 and the minimum happiness is 0.
Now it's your turn to find an arrangement for the real problem with 1000 elves in which everyone is as happy as possible!
Good luck and happy coding! 🎄📸