Matrix Operations (Making a Beautiful Matrix)
Time limit2sMemory limit1024 MB
From the N by N upper triangular matrix of ones, add p/q to whole rows or columns within 2N operations so every absolute row and column sum is at most N/4.
- Level
Medium7 of 10
- Topics
- Matrix, Math, Implementation
- Solved
- No attempts yet
Problem
matrix is defined as follows. is the value in row and column .
In other words, has on the main diagonal and on every position above it, and everywhere else. For example:
The following operations can be applied to this matrix.
- : Choose integers , , . Add to every element in row . (, , )
- : Choose integers , , . Add to every element in column . (, , )
A matrix is called beautiful if, for every row and every column, the sum of the absolute values of its elements is at most . Formally, an by matrix is beautiful if the following holds for all and .
Starting from , you can apply at most operations to turn the matrix into a beautiful matrix. Find one such sequence of operations and output it.
Input
The first line contains the integer , the size of the matrix. ()
Output
On the first line, print the number of operations . It must satisfy .
On each of the next lines, print four integers separated by spaces that describe one operation. Each operation must be one of the following.
- (, , )
- (, , )
After all operations are applied in order to the matrix initialized as , the result must be a beautiful matrix.