codeforces-scrape

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

203B.md (2239B)


      1 Source: https://codeforces.com/problemset/problem/203/B
      2 
      3 B. Game on Paper
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.
     22 
     23 He took a checkered white square piece of paper, consisting of *n* × *n* cells. After that, he started to paint the white cells black one after the other. In total he painted *m* different cells on the piece of paper. Since Valera was keen on everything square, he wondered, how many moves (i.e. times the boy paints a square black) he should make till a black square with side 3 can be found on the piece of paper. But Valera does not know the answer to this question, so he asks you to help him.
     24 
     25 Your task is to find the minimum number of moves, till the checkered piece of paper has at least one black square with side of 3. Otherwise determine that such move does not exist.
     26 
     27 Input
     28 
     29 The first line contains two integers *n* and *m* (1 ≤ *n* ≤ 1000, 1 ≤ *m* ≤ *min*(*n*·*n*, 105)) — the size of the squared piece of paper and the number of moves, correspondingly.
     30 
     31 Then, *m* lines contain the description of the moves. The *i*-th line contains two integers *x**i*, *y**i* (1 ≤ *x**i*, *y**i* ≤ *n*) — the number of row and column of the square that gets painted on the *i*-th move.
     32 
     33 All numbers on the lines are separated by single spaces. It is guaranteed that all moves are different. The moves are numbered starting from 1 in the order, in which they are given in the input. The columns of the squared piece of paper are numbered starting from 1, from the left to the right. The rows of the squared piece of paper are numbered starting from 1, from top to bottom.
     34 
     35 Output
     36 
     37 On a single line print the answer to the problem — the minimum number of the move after which the piece of paper has a black square with side 3. If no such move exists, print -1.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 4 11  
     45 1 1  
     46 1 2  
     47 1 3  
     48 2 2  
     49 2 3  
     50 1 4  
     51 2 4  
     52 3 4  
     53 3 2  
     54 3 3  
     55 4 1
     56 ```
     57 
     58 Output
     59 
     60 ```
     61 10
     62 ```
     63 
     64 Input
     65 
     66 ```
     67 4 12  
     68 1 1  
     69 1 2  
     70 1 3  
     71 2 2  
     72 2 3  
     73 1 4  
     74 2 4  
     75 3 4  
     76 3 2  
     77 4 2  
     78 4 1  
     79 3 1
     80 ```
     81 
     82 Output
     83 
     84 ```
     85 -1
     86 ```