Treasure
Time limit2sMemory limit256 MB
Find all treasure cells on an N x N grid by asking rectangle count queries whose cost grows as the rectangle shrinks.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Binary search, Intervals, Greedy
- Solved
- No attempts yet
Problem
After a recent earthquake, a new island rose in the Adriatic Sea. Most of the island is barren, but archaeologists found a strange device that people now call the oracle. It came with no manual, yet a joint team of archaeologists and computer scientists figured out how it works.
The oracle reports where treasure is buried on the island. The island is an grid. Rows and columns are numbered from 1 through . Some cells contain treasure. The oracle answers questions of the form: how many cells inside a given axis-aligned rectangle contain treasure?
If a rectangle covers cells, answering that question costs exactly energy. Smaller rectangles cost more.
Write a program that interacts with the oracle and finds every cell that contains treasure. Keep the total energy use low.
Interaction
Your program reads from standard input, then alternates queries and answers with the oracle.
Query: print one line with four integers , the inclusive rectangle from row , column to row , column . (, )
Answer: one line with the number of treasure cells inside that rectangle. A blank line follows each answer.
When every treasure cell is known, print END, then print the grid in lines. Each line is a length- string of 0 and 1. Use 1 for treasure and 0 for empty cells.
Constraints
- The number of treasure cells is between 0 and , inclusive.