codeforces-scrape

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

745B.md (2397B)


      1 Source: https://codeforces.com/problemset/problem/745/B
      2 
      3 B. Hongcow Solves A Puzzle
      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 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Hongcow likes solving puzzles.
     22 
     23 One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.
     24 
     25 The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.
     26 
     27 You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position.
     28 
     29 Input
     30 
     31 The first line of input will contain two integers *n* and *m* (1 ≤ *n*, *m* ≤ 500), the dimensions of the puzzle piece.
     32 
     33 The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
     34 
     35 It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region.
     36 
     37 Output
     38 
     39 Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 2 3  
     47 XXX  
     48 XXX
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 YES
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 2 2  
     61 .X  
     62 XX
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 NO
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 5 5  
     75 .....  
     76 ..X..  
     77 .....  
     78 .....  
     79 .....
     80 ```
     81 
     82 Output
     83 
     84 ```
     85 YES
     86 ```
     87 
     88 Note
     89 
     90 For the first sample, one example of a rectangle we can form is as follows
     91 
     92 ```
     93 111222  
     94 111222
     95 ```
     96 
     97 For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
     98 
     99 In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
    100 
    101 ```
    102 .....  
    103 ..XX.  
    104 .....  
    105 .....  
    106 .....
    107 ```