codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1453C.md (3646B)


      1 Source: https://codeforces.com/problemset/problem/1453/C
      2 
      3 C. Triangles
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Gildong has a square board consisting of $n$ rows and $n$ columns of square cells, each consisting of a single digit (from $0$ to $9$). The cell at the $j$-th column of the $i$-th row can be represented as $(i, j)$, and the length of the side of each cell is $1$. Gildong likes big things, so for each digit $d$, he wants to find a triangle such that:
     22 
     23 * Each vertex of the triangle is in the center of a cell.
     24 * The digit of every vertex of the triangle is $d$.
     25 * At least one side of the triangle is parallel to one of the sides of the board. You may assume that a side of length $0$ is parallel to both sides of the board.
     26 * The area of the triangle is maximized.
     27 
     28 Of course, he can't just be happy with finding these triangles as is. Therefore, for each digit $d$, he's going to change the digit of exactly one cell of the board to $d$, then find such a triangle. He changes it back to its original digit after he is done with each digit. Find the maximum area of the triangle he can make for each digit.
     29 
     30 Note that he can put multiple vertices of the triangle on the same cell, and the triangle can be a [degenerate triangle](https://cutt.ly/NhbjZ2l); i.e. the area of the triangle can be $0$. Also, note that he is allowed to change the digit of a cell from $d$ to $d$.
     31 
     32 Input
     33 
     34 Each test contains one or more test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$).
     35 
     36 The first line of each test case contains one integer $n$ ($1 \le n \le 2000$) — the number of rows and columns of the board.
     37 
     38 The next $n$ lines of each test case each contain a string of $n$ digits without spaces. The $j$-th digit of the $i$-th line is the digit of the cell at $(i, j)$. Each digit is one of the characters from $0$ to $9$.
     39 
     40 It is guaranteed that the sum of $n^2$ in all test cases doesn't exceed $4 \cdot 10^6$.
     41 
     42 Output
     43 
     44 For each test case, print one line with $10$ integers. The $i$-th integer is the maximum area of triangle Gildong can make when $d = i-1$, multiplied by $2$.
     45 
     46 Example
     47 
     48 Input
     49 
     50 ```
     51 5
     52 3
     53 000
     54 122
     55 001
     56 2
     57 57
     58 75
     59 4
     60 0123
     61 4012
     62 3401
     63 2340
     64 1
     65 9
     66 8
     67 42987101
     68 98289412
     69 38949562
     70 87599023
     71 92834718
     72 83917348
     73 19823743
     74 38947912
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 4 4 1 0 0 0 0 0 0 0
     81 0 0 0 0 0 1 0 1 0 0
     82 9 6 9 9 6 0 0 0 0 0
     83 0 0 0 0 0 0 0 0 0 0
     84 18 49 49 49 49 15 0 30 42 42
     85 ```
     86 
     87 Note
     88 
     89 In the first case, for $d=0$, no matter which cell he chooses to use, the triangle with vertices at $(1, 1)$, $(1, 3)$, and $(3, 1)$ is the biggest triangle with area of $\cfrac{2 \cdot 2}{2} = 2$. Since we should print it multiplied by $2$, the answer for $d=0$ is $4$.
     90 
     91 For $d=1$, Gildong can change the digit of the cell at $(1, 3)$ into $1$, making a triangle with vertices on all three $1$'s that has an area of $2$.
     92 
     93 For $d=2$, Gildong can change the digit of one of the following six cells into $2$ to make a triangle with an area of $\cfrac{1}{2}$: $(1, 1)$, $(1, 2)$, $(1, 3)$, $(3, 1)$, $(3, 2)$, and $(3, 3)$.
     94 
     95 For the remaining digits (from $3$ to $9$), the cell Gildong chooses to change will be the only cell that contains that digit. Therefore the triangle will always be a degenerate triangle with an area of $0$.
     96 
     97 In the third case, for $d=4$, note that the triangle will be bigger than the answer if Gildong changes the digit of the cell at $(1, 4)$ and use it along with the cells at $(2, 1)$ and $(4, 3)$, but this is invalid because it violates the condition that at least one side of the triangle must be parallel to one of the sides of the board.