codeforces-scrape

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

729B.md (2161B)


      1 Source: https://codeforces.com/problemset/problem/729/B
      2 
      3 B. Spotlights
      4 
      5 time limit per test
      6 
      7 1 second
      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 Theater stage is a rectangular field of size *n* × *m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
     22 
     23 You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.
     24 
     25 A position is good if two conditions hold:
     26 
     27 * there is no actor in the cell the spotlight is placed to;
     28 * there is at least one actor in the direction the spotlight projects.
     29 
     30 Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.
     31 
     32 Input
     33 
     34 The first line contains two positive integers *n* and *m* (1 ≤ *n*, *m* ≤ 1000) — the number of rows and the number of columns in the plan.
     35 
     36 The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.
     37 
     38 Output
     39 
     40 Print one integer — the number of good positions for placing the spotlight.
     41 
     42 Examples
     43 
     44 Input
     45 
     46 ```
     47 2 4  
     48 0 1 0 0  
     49 1 0 1 0
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 9
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 4 4  
     62 0 0 0 0  
     63 1 0 0 1  
     64 0 1 1 0  
     65 0 1 0 0
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 20
     72 ```
     73 
     74 Note
     75 
     76 In the first example the following positions are good:
     77 
     78 1. the (1, 1) cell and right direction;
     79 2. the (1, 1) cell and down direction;
     80 3. the (1, 3) cell and left direction;
     81 4. the (1, 3) cell and down direction;
     82 5. the (1, 4) cell and left direction;
     83 6. the (2, 2) cell and left direction;
     84 7. the (2, 2) cell and up direction;
     85 8. the (2, 2) and right direction;
     86 9. the (2, 4) cell and left direction.
     87 
     88 Therefore, there are 9 good positions in this example.