SHARE
TWEET

Untitled

PikMike Apr 29th, 2017 224 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2.  
  3. N=int(sys.stdin.readline())
  4. seq=list(map(int,sys.stdin.readline().split()))
  5. INF=1000000000
  6. ans=[INF for i in range (N)]
  7.      
  8. ptr=INF
  9. for i in range (N) :
  10.    j=N-i-1
  11.    if(seq[j]==0):
  12.        ptr=j
  13.    ans[j]=ptr-j
  14.  
  15. ptr=-INF
  16. for i in range (N) :
  17.    if(seq[i]==0):
  18.        ptr=i
  19.    ans[i]=min(ans[i], i-ptr)
  20.            
  21. answer = ' '.join(map(str, ans))
  22. sys.stdout.write(answer)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top