codeforces-scrape

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

1368C.md (2357B)


      1 Source: https://codeforces.com/problemset/problem/1368/C
      2 
      3 C. Even Picture
      4 
      5 time limit per test
      6 
      7 2 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 Leo Jr. draws pictures in his notebook with checkered sheets (that is, each sheet has a regular square grid printed on it). We can assume that the sheets are infinitely large in any direction.
     22 
     23 To draw a picture, Leo Jr. colors some of the cells on a sheet gray. He considers the resulting picture beautiful if the following conditions are satisfied:
     24 
     25 * The picture is connected, that is, it is possible to get from any gray cell to any other by following a chain of gray cells, with each pair of adjacent cells in the path being neighbours (that is, sharing a side).
     26 * Each gray cell has an even number of gray neighbours.
     27 * There are exactly $n$ gray cells with all gray neighbours. The number of other gray cells can be arbitrary (but reasonable, so that they can all be listed).
     28 
     29 Leo Jr. is now struggling to draw a beautiful picture with a particular choice of $n$. Help him, and provide any example of a beautiful picture.
     30 
     31 To output cell coordinates in your answer, assume that the sheet is provided with a Cartesian coordinate system such that one of the cells is chosen to be the origin $(0, 0)$, axes $0x$ and $0y$ are orthogonal and parallel to grid lines, and a unit step along any axis in any direction takes you to a neighbouring cell.
     32 
     33 Input
     34 
     35 The only line contains a single integer $n$ ($1 \leq n \leq 500$) — the number of gray cells with all gray neighbours in a beautiful picture.
     36 
     37 Output
     38 
     39 In the first line, print a single integer $k$ — the number of gray cells in your picture. For technical reasons, $k$ should not exceed $5 \cdot 10^5$.
     40 
     41 Each of the following $k$ lines should contain two integers — coordinates of a gray cell in your picture. All listed cells should be distinct, and the picture should satisdfy all the properties listed above. All coordinates should not exceed $10^9$ by absolute value.
     42 
     43 One can show that there exists an answer satisfying all requirements with a small enough $k$.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 4
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 12
     57 1 0
     58 2 0
     59 0 1
     60 1 1
     61 2 1
     62 3 1
     63 0 2
     64 1 2
     65 2 2
     66 3 2
     67 1 3
     68 2 3
     69 ```
     70 
     71 Note
     72 
     73 The answer for the sample is pictured below:
     74 
     75  ![](https://espresso.codeforces.com/32d3333414209636f4bf5f77aeae92fca88b7155.png)