Aquarelle
Time limit0.4sMemory limit1024 MB
Given color sets for N cells and an initial painted range l to r, decide if the rest can be painted so each new cell adds an unseen color.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Intervals, Hash map
- Solved
- No attempts yet
Problem
Marincho loves to paint with watercolors. He wants to make a color sequence of cells. For each cell (), he picks a set of colors of size , mixes them, and paints the cell with the result.
He has already painted cells through using . He now paints the remaining cells in a fixed order. The next cell to paint is cell or , whichever exists. If the painted cells are through , the next cell is:
- If and , all cells are painted.
- If and , the next cell is .
- If and , the next cell is .
- If and , the next cell is or .
After painting cells through , Marincho finds the sequence too monochromatic. Every cell he paints from now on must contain at least one new color, one that appears in no cell painted so far. Write a program aquarelle that determines whether the remaining cells can all be painted. Answer this for each of the initial paintings.
Input
The first line contains . Each of the next lines contains followed by the colors , which are distinct positive integers. The next line contains . Each of the last lines contains and . Numbers on a line are separated by one space.
- ,
Output
For each initial painting, in input order, print 1 if the remaining cells can be painted, otherwise print 0.
Hint
Let us analyze the first initial painting. An optimal order is shown in the table below.
Note that if cell 5 were painted first, the painting could not be completed.
Let us analyze the third initial painting.
Note that if cell 6 were painted first, the later steps would be the same and the painting would still fail. The answer here is 0.