codeforces-scrape

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

803B.md (1041B)


      1 Source: https://codeforces.com/problemset/problem/803/B
      2 
      3 B. Distances to Zero
      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 You are given the array of integer numbers *a*0, *a*1, ..., *a**n* - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
     22 
     23 Input
     24 
     25 The first line contains integer *n* (1 ≤ *n* ≤ 2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ *a**i* ≤ 109).
     26 
     27 Output
     28 
     29 Print the sequence *d*0, *d*1, ..., *d**n* - 1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j* = 0. It is possible that *i* = *j*.
     30 
     31 Examples
     32 
     33 Input
     34 
     35 ```
     36 9  
     37 2 1 0 3 0 0 3 2 4
     38 ```
     39 
     40 Output
     41 
     42 ```
     43 2 1 0 1 0 0 1 2 3
     44 ```
     45 
     46 Input
     47 
     48 ```
     49 5  
     50 0 1 2 3 4
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 0 1 2 3 4
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 7  
     63 5 6 0 1 -2 3 4
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 2 1 0 1 2 3 4
     70 ```