EN
A wall of light bulbs on Ban Jelačić Square

2026 · Task 1

The Light Bulb Tree

Author: Dominik Kanjuh

30/11/2026 00:01 – 20/12/2026 23:59

This year, something special is shining on Ban Jelačić Square in Zagreb: a giant wall of 100 × 100 = 10000 light bulbs. Santa already knows what he wants to see on it: a Christmas tree packed with baubles, with a star on top, in the middle of a snowy night.

The only problem? The elves did the wiring. There are 5000 switches waiting in the junction box, and each one flips 24 to 32 bulbs scattered all over the wall. No bulb has been forgotten (every one is wired to at least one switch), but there isn't a shred of logic in the wiring.

When you press a switch, all of its bulbs flip: the ones that are on go off, and the ones that are off light up. At the start, the whole wall is dark. There are twice as many bulbs as switches, so a perfect picture is almost certainly impossible, but Santa is hoping you'll get as close as you can.

He has two wishes. The tree and the star have to look brilliant, while the snow and the sky can wait a little. And don't go overboard with the switches: each one uses electricity, and to reach some of them the elves have to climb ladders.

Which switches will you press?

Input

  • First line: two integers N K separated by a space. In the real data this is 100 5000: the wall is N × N and there are K switches.
  • Next N lines: Santa's picture. Each line has exactly N characters 0 or 1 (no spaces). The character in row r and column c says whether bulb (r, c) should be on (1) or off (0). Rows and columns are numbered from 1, row 1 is at the top, column 1 on the left.
  • Next N lines: the importance of each bulb, in the same format, each character a single digit. In the real data, bulbs on the star and the tree have importance 3, and all others 1.
  • Next K lines: the switches in order from 1 to K. Line j starts with the cost of switch j (an integer from 1 to 9), followed by the list of bulbs it flips, written as r,c (row, column). Everything is separated by a single space. No bulb appears twice on the same line. In the real data, each switch flips 24 to 32 bulbs.

Output

A single line with exactly K characters 0 or 1 (no spaces). The j-th character is 1 if you press switch j and 0 if you don't. You may end with a newline.

Any such string is a valid answer. Anything else (wrong length, other characters) is an invalid answer.

Example output (shortened):

0110100000101100...0001

Scoring

An invalid answer gets 0 points, a valid one between 1 and 100 000 points.

At the end, a bulb is on if an odd number of the switches that flip it were pressed, otherwise it is off. A bulb is wrong if its state differs from Santa's picture.

  • Ew = total importance of all wrong bulbs
  • C = sum of the costs of all pressed switches
  • S = 2 × Ew + C (lower is better)
  • W = total importance of all bulbs on the wall (in the real data W = 15096)

A perfect picture without pressing a single switch would give S = 0. That's impossible, but it's exactly the dream we use to measure how close you get:

q = max(0, W − S) / W, rounded to 6 decimal places (halves round up)

Points = 1 + 99 999 × q

Kontestis rounds the points to a whole number.

For comparison: if you press no switches at all, every bulb stays off, Ew = 6658, C = 0, S = 13316 and you get 11 792.08 points.

Example

A small 4 × 4 wall with 5 switches (the top of a tree).

Input

4 5
0110
0110
1111
0000
1331
1331
3333
1111
2 1,1 1,2 2,2 2,3
5 1,3 1,4 3,1 4,2
1 3,1 3,2 3,3 3,4
3 1,2 1,3 2,1 4,4
4 2,2 2,4 3,3 4,1 4,3

The total importance is W = 8 + 8 + 12 + 4 = 32.

Output

10100

Switches 1 (cost 2) and 3 (cost 1) are pressed. Switch 1 flips (1,1), (1,2), (2,2), (2,3), and switch 3 flips the whole third row. The wall ends up like this (your wall on the left, Santa's picture on the right):

1100    0110
0110    0110
1111    1111
0000    0000

The wrong bulbs are (1,1) with importance 1 and (1,3) with importance 3, so Ew = 4. The cost is C = 2 + 1 = 3.

  • S = 2 × 4 + 3 = 11
  • q = (32 − 11) / 32 = 0.65625 (only 5 decimal places, so no rounding)
  • Points = 1 + 99 999 × 0.65625 = 65 625.34375 → 65 625.34

This is the best of all 32 possible answers for the small wall.

If you also press switch 4 (answer 10110), you fix (1,3) but break (1,2), (2,1) and (4,4): Ew = 1 + 3 + 1 + 1 = 6, C = 6, S = 18, q = 14/32 = 0.4375, and the points are 1 + 99 999 × 0.4375 = 43 750.56.

The answer 00000 (pressing nothing) gives Ew = 24, S = 48 > W, so q = 0 and you get 1 point.

The answer 1010 is invalid (it has 4 characters instead of 5) and gets 0 points. The same goes for 10120.

Once you've built your wall, draw it and show Santa the picture. He'll be delighted!

Good luck and happy coding! 🎄💡

Kontestis join code: 643ffc40917b6fa6

Before submitting, join the contest on kontestis.ac (Contests → Join contest). Submissions made without joining won't count.