Advertisement
PikMike

Untitled

Apr 29th, 2017
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement