Chef and Number Guessing
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a rectangular matrix A of nxm integers. Rows are numbered by integers from 1 to n from top to bottom, columns - from 1 to m from left to right. Ai, j denotes the j-th integer of the i-th row.
Chef wants you to guess his matrix. To guess integers, you can ask Chef questions of next type: "How many integers from submatrix iL, iR, jL, jR are grater than or equal to x and less than or equal to y?". By submatrix iL, iR, jL, jR we mean all elements Ai, j for all iL ≤ i ≤ iR and jL ≤ j ≤ jR.
Also Chef can answer not more than C questions of next type: "What is the sum of integers from submatrix iL, iR, jL, jR?"
As soon as you think you know the Chefs matrix, you can stop asking questions and tell to the Chef your variant of the matrix. Please see "Scoring" part to understand how your solution will be evaluated.
The first line of the input contains three space-separated integers n, m and C denoting the sizes of the matrix and the maximum number of the second-type questions. After that the judge will answer your questions and evaluate the resuts. Read more about that in the "Interaction with the judge" part of the statement.
Interaction with the judge
To ask a first-type question you should print to the standard output one line containing seven space-separated integers 1 iL iR jL jR x y. To ask a second-type question you should print one line containing five space-separated integers 2 iL iR jL jR. After that you should read from the standard input one integer - answer to the question. To end the game you should print 3 and starting from next line print n lines, each of them contains m space-separated integers - your variant of the matrix A. After that your program must stop. Remember to flush the output after every line you print.
- 1 ≤ n, m ≤ 2.5 * 105
- 1 ≤ n * m ≤ 2.5 * 105
- 103 ≤ C ≤ 104
- 1 ≤ Ai, j ≤ 50
- 1 ≤ iL ≤ iR ≤ n
- 1 ≤ jL ≤ jR ≤ m
- 1 ≤ x ≤ y ≤ 50
- 0 ≤ number of asked questions ≤ 5 * 105
- 1 ≤ Bi, j ≤ 50
- 1 ≤ a1, a2, a3 ≤ 10
Let B will be the matrix you output and diff = ∑ |Ai, j - Bi, j| for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. The number of questions you asked is questions. The number of integers, you correctly guessed is correct(i. e. the number of elements i, j such that Ai, j = Bi, j).
The score for each test case will be: score = a1 * questions + a2 * diff + a3 * (n * m - correct).
Your goal is to minimize this score.
Your total score for the problem will be the sum of scores on all the test cases.
Input: 3 3 10 4 0 3 1 6 Output: 1 1 2 1 2 1 3 1 3 3 1 3 1 1 1 3 3 1 3 2 2 1 1 2 3 3 1 1 2 3 3 1 3 3 2 2 1 2 2 1 2 2 2
[1, 2, 3] A = [3, 2, 1] [2, 2, 2]
For this test case a1 = 1, a2 = 1 and a3 = 1.
The score for this test case will be 1 * 5 + 1 * 4 + 1 * (9 - 6) = 12.
Test data generation
There will be four types of the test files.
- Type #1: n = 10, m = 25000
- Type #2: n = 100, m = 2500
- Type #3: n = 250, m = 1000
- Type #4: n = 500, m = 500
There will be 5 test files of each type. During the contest, you will be shown the score for only one test file of each type.
All elements of matrix A are randomly chosen.
For each test case C is randomly chosen from interval [103 .. 104].
For each test case values a1, a2 and a3 are manually chosen.
|Tags||antoniuk1, binary-search, challenge, march16|
|Time Limit:||4 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.