Problem:


Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.
Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 2 \times 10^5

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2 

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3 



Sample input:
5 1
1 0 0 1 0


Sample output:
1 2 2 1 2

Submission status: Wrong Answer

Solution code:
import numpy as np


### 解答
N, K = map(int, input().split())
A = np.asarray(list(map(int, input().split())), dtype=np.int)

#B = [0]*N                                 # 記録用のリスト

def imos(A):      
  B = np.zeros(N)
  for i in range(N):                      # 各電球によって照らされる範囲を考える
    start = max(0, i-A[i])                # 始点のインデックスは0かi-A[i]
    end = min(N, i+A[i]+1)
    print(start, end)                # 終点のインデックスはNかi+A[i]+1
    B[start] += 1                         # 始点に+1を記録する
    if end <= N - 1:
      B[end] -= 1                         # 終点に電球が存在する場合は-1を記録する
  A = np.cumsum(B).astype(np.int)
  return A




for k in range(K):                        # 以降の操作をK回繰り返す
  A = imos(A)
  if np.min(A) == N:
    break
print(*A)                                 # リストAの中身を順に表示

Submission status: Wrong Answer

Solution code:
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

for _ in range(K):
    _A = list(A)
    for i in range(N):
        count = 1
        for j,y in enumerate(_A):
            if j != i and y >= abs(j-i):
                count += 1
        A[i] =  count
print(A)

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,36)):
  
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  
  if a[:n]==[n]*n:
    break
print(*a[:n])

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,35)):
  
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  
  if a[:n]==[n]*n:
    break
print(*a[:n])

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,34)):
  
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  
  if a[:n]==[n]*n:
    break
print(*a[:n])

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,32)):
  
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  
  if a[:n]==[n]*n:
    break
print(*a[:n])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = A[:]
for k in range(K):
    ans_new = [0] * N
    for n in range(N):
        a = ans[n]
        for i in range(n-a, n+a+1):
            if 0 <= i < N:
                #print(n, i)
                ans_new[i] += 1
    ans = ans_new[:]
    if sum(ans) == N * N:
        break
    #print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def main(n,k,a):
  for _ in range(k):
    b=[0]*(n+1)
    for i,j in enumerate(a):
      if i-j<0:
        b[0]+=1
      else:
        b[i-j]+=1
      if i+j+1<n:
        b[i+j+1]-=1
    for i in range(1,n):
      b[i]+=b[i-1]
    if a==b:break
    a=b
  print(*a[:-1])
N,K,*A=map(int,open(0).read().split())
main(N,K,A)

Submission status: Wrong Answer

Solution code:
#coding; utf-8
import copy
N, k = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * N
A = [0] + A
#B = copy.copy(A)
#k = 10
for j in range(k):
    #print(A)
    n_light = [0] * (N+1)
    for i in range(N):
        d = A[i+1]
        l = i+1-d
        r = i+1+d
        #print(l, r)
        n_light[max(l, 1)] += 1
        if r+1 <= N:# and l != r:
            n_light[r+1] -= 1
        #print(n_light)
    #print(n_light)
    for i in range(1,N):
        n_light[i+1] += n_light[i]
    n_str = [str(i) for i in n_light]
    if len(set(n_light[1:])) == 1:
        #print(n_light)
        break
    #n_str = [str(i) for i in n_light]
    A = n_light 
print(' '.join(n_str[1:]))

Submission status: Wrong Answer

Solution code:
#coding; utf-8
import copy
N, k = map(int,input().split())
A = list(map(int,input().split()))
B = [0] * N
A = [0] + A
#B = copy.copy(A)
k = 10
for j in range(k):
    #print(A)
    n_light = [0] * (N+1)
    for i in range(N):
        d = A[i+1]
        l = i+1-d
        r = i+1+d
        #print(l, r)
        n_light[max(l, 1)] += 1
        if r+1 <= N:# and l != r:
            n_light[r+1] -= 1
        #print(n_light)
    #print(n_light)
    for i in range(1,N):
        n_light[i+1] += n_light[i]
    n_str = [str(i) for i in n_light]
    if len(set(n_light[1:])) == 1:
        #print(n_light)
        break
    #n_str = [str(i) for i in n_light]
    A = n_light 
print(' '.join(n_str[1:]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
width = [0 for _ in range(N)]

for k in range(50):
    cnt = 0
    for i in range(N):
        if i-A[i]-0.5 < 0:
            left = int(i-A[i]-0.5)
        else:
            left = int(i-A[i]-0.5) + 1
        right = int(i+A[i]+0.5)
        if left < 0:
            left = 0
        if right > N-1:
            right = N - 1
        if left == 0 and right == len(A)-1:
            cnt += 1
        width[left:right+1] = map(lambda x: x+1, width[left:right+1])
    A = width.copy()
    if cnt == N:
        break
    width = [0 for _ in range(N)]

for i in range(N-1):
    print(A[i], end=" ")
print(A[N-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
width = [0 for _ in range(N)]

for k in range(100):
    cnt = 0
    for i in range(N):
        if i-A[i]-0.5 < 0:
            left = int(i-A[i]-0.5)
        else:
            left = int(i-A[i]-0.5) + 1
        right = int(i+A[i]+0.5)
        if left < 0:
            left = 0
        if right > N-1:
            right = N - 1
        if left == 0 and right == len(A)-1:
            cnt += 1
        width[left:right+1] = map(lambda x: x+1, width[left:right+1])
    A = width.copy()
    if cnt == N:
        break
    width = [0 for _ in range(N)]

for i in range(N-1):
    print(A[i], end=" ")
print(A[N-1])

Submission status: Wrong Answer

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import numpy as np
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()

imos_l=[0]*(N+1)

for i in range(K):    
    imos_l=[0]*(N+1)
    for j in range(len(A)): 
        imos_l[max(j-A[j],0)]+=1
        imos_l[min(j+A[j]+1,N)]-=1
    for j in range(len(imos_l)-1):
        imos_l[j+1]=imos_l[j]+imos_l[j+1]
    for j in range(len(A)):
        A[j]=imos_l[j]
    flag=True
    for j in range(len(A)):
        if(A[j]<K):
            flag=False
    if(flag):
        print(*A)
        sys.exit(0)

print(*A)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(K):
        b = [0] * (N+1)
        for j in range(N):
            a = A[j]
            b[max(j-a, 0)] += 1
            b[min(j+a+1, N)] -= 1
        for k in range(1,N+1):
            b[k] += b[k-1]
        b = b[:N]
        print(b)
        if b == A:
            break
        else:
            A = b
    print(*A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))


for j in range(41):
    b=[0]*n
    for i in range(0,n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if(r+1<n):
            b[r+1]-=1
    for i in range(1,n,1):
        b[i]+=b[i-1]
    if a==b:
        break
    a=b

print(' '.join(map(str,a)))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))

for q in range(42):
  b = [0]*(n+1)
  for i in range(n):
    l = max(0, i-a[i])
    r = min(i+a[i]+1, n)
    b[l] += 1
    if r <= n-1: b[r] -= 1
  
  B = np.array(b)
  a = B.cumsum()[:-1]
  
  if np.all(a == n):
    break

print(*a)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
light=list(map(int,input().split()))
for k in range(42):
  imo=[0]*(N+1)
  for i in range(N):
    l=max(0,i-light[i])
    r=min(N-1,i+light[i])+1
    imo[l]+=1
    imo[r]-=1
  for i in range(1,N):
    imo[i]+=imo[i-1]
  light=imo[:]
print(*light[:-1])

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
light=list(map(int,input().split()))
copy=[0]*N
for k in range(K):
  imo=[0]*(N+1)
  x=0
  for i in range(N):
    kido=light[i]
    imo[max(0,i-kido)]+=1
    imo[min(N-1,i+kido)+1]-=1
  for j in range(N):
    x+=imo[j]
    copy[j]=x
  if light==copy:
    break
  else:
    light=copy
print(*light)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
list = list(map(int, input().split()))

for k_ in range(k):
    list_ = [0] * n

    for i in range(n):
        for j in range(n):
            if i == j:
                list_[i] += 1
                continue
            if i > j and j + list[j] >= i:
                list_[i] += 1
                continue
            
            if i < j and j - list[j] <= i:
                list_[i] += 1
                continue
    
    list = list_

print(list)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np
input = sys.stdin.readline

n, k = map(int, input().split())
a= np.array(list(map(int,input().split())))
b = np.zeros(n,dtype='int')
c = np.zeros(n,dtype='int')
A = np.hstack([b,a,c])
print(A)
for i in range(k):
    l = np.zeros(3*n,dtype='int')
    for j in range(n,2*n,1):
        l[j-A[j]:j+A[j]+1]   += np.array([1])
    A = l
    if all(A[n:2*n] == n):
        print(A[n:2*n])
        sys.exit()
      

print(A[n:2*n])

Submission status: Wrong Answer

Solution code:
# tokiomarine2020_c.py
'''
imos 法を使って解くらしい
類題
https://atcoder.jp/contests/abc014/tasks/abc014_3
'''
import math
def calc(a):
    ret = []
    cumsum=0
    isOver = True
    for i in a:
        # print("i,N",i,N)
        cumsum += i
        ret.append(min(N,cumsum))
        if cumsum <= N:
            isOver = False
    return  ret[:5],isOver
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K):
    ans = [0]*(N+2)
    for j,v in enumerate(A):
        head = max(0,math.ceil(j-v-0.5))
        tail = min(N,math.floor(j+v+0.5))
        ans[head]+=1
        ans[tail+1]-=1
    A ,flg= calc(ans[:N])
    if flg:
        A = [N]*N
        break
print(*A)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
List = list(map(int, input().split()))
data_x = [0]*N
res = [0]*N

def imosu(x,k):
  data = [0]*k
  ruiseki = [0]*k
  for i in range(k):
    first = i-x[i]
    last = i+x[i]
    if first < 0:
      first = 0
    data[first] += 1
    if last+1 < k:
      data[last+1] +=-1
  ruiseki[0] = data[0]
  for i in range(k-1):
    ruiseki[i+1] = ruiseki[i] + data[i+1]
  return ruiseki

for i in range(K):
  Flag = False
  List = imosu(List,N)
  if List.count(N) == N:
      Flag = True
  print(Flag)
  if Flag:
    break
print(*List)

Submission status: Wrong Answer

Solution code:
buf = list(map(int, input().split()))
N=buf[0]
K=buf[1]
A = list(map(int, input().split()))

for k in range(K):
  B=[0]*len(A)
  for a in range(len(A)-1):
    for i in range(a-A[a],a+A[a]+1):
      try:
        B[i]=B[i]+1
      except:
        pass
  A=B
print(" ".join([str(a) for a in A]))

Submission status: Wrong Answer

Solution code:
import numpy as np
from numba import njit


@njit
def get_a(n, k, a):
    for _ in range(k):
        B = [0] * (n + 1)
        for i in range(n):
            l = max(0, i - a[i])
            r = min(n - 1, i + a[i])
            B[l] += 1
            if r + 1 < n:
                B[r + 1] -= 1

        for i in range(n):
            B[i] += B[i - 1]

        a = B[:-1]

    print(a)


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    get_a(N, K, A)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [a for a in map(int, input().split())]

for _ in range(K):
    B = [0] * (N + 1)
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    for i in range(N):
        B[i] += B[i - 1]

    A = B[:-1]

print(A)

Submission status: Wrong Answer

Solution code:
# tokiomarine2020_c.py
'''
imos 法を使って解くらしい
類題
https://atcoder.jp/contests/abc014/tasks/abc014_3
'''
import math
def calc(a):
    ret = []
    cumsum=0
    isOver = True
    for i in a:
        # print("i,N",i,N)
        cumsum+=i
        ret.append(min(N,cumsum))
        if cumsum < N:
            isOver = False
    return  ret[:5],isOver
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K):
    ans = [0]*(N+2)
    for j,v in enumerate(A):
        head = max(0,math.ceil(j-v-0.5))
        tail = min(N,math.floor(j+v+0.5))
        ans[head]+=1
        ans[tail+1]-=1
    A ,flg= calc(ans[:N])
    if flg:
        A = [N]*N
        break
print(*A)

Submission status: Wrong Answer

Solution code:
# tokiomarine2020_c.py
'''
imos 法を使って解くらしい
類題
https://atcoder.jp/contests/abc014/tasks/abc014_3
'''
import math
def calc(a):
    ret = []
    cumsum=0
    isOver = True
    for i in a:
        cumsum+=i
        ret.append(min(N,cumsum))
        # ret.append(cumsum)
        if cumsum<N:
            isOver = False
    return  ret[:5],isOver
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K):
    ans = [0]*(N+2)
    for j,v in enumerate(A):
        head = max(0,math.ceil(j-v-0.5))
        tail = min(N,math.floor(j+v+0.5))
        ans[head]+=1
        ans[tail+1]-=1
    A ,flg= calc(ans)
    if flg:
        A = [N]*N
print(*A)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
List = list(map(int, input().split()))
data_x = [0]*N
res = [0]*N

def imosu(x,k):
  data = [0]*k
  for i in range(k):
    first = i-x[i]
    last = i+x[i]
    if first < 0:
      first = 0
    data[first] += 1
    if last+1 < k:
      data[last+1] +=-1
  return data

def ruiseki_f(y, k):
  ruiseki = [0]*k
  ruiseki[0] = y[0]
  for i in range(k-1):
    ruiseki[i+1] = ruiseki[i] + y[i+1]
  return ruiseki

for i in range(K):
  data_x = imosu(List,N)
  List = ruiseki_f(data_x,N)
res = List
print(res)

Submission status: Wrong Answer

Solution code:
# tokiomarine2020_c.py
'''
imos 法を使って解くらしい
類題
https://atcoder.jp/contests/abc014/tasks/abc014_3
'''
import math
def calc(a):
    ret = []
    cumsum=0
    isOver = True
    for i in a:
        cumsum+=i
        ret.append(cumsum)
        if cumsum<N:
            isOver = False
    return  ret[:5],isOver
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K):
    ans = [0]*(N+2)
    for j,v in enumerate(A):
        head = max(0,math.ceil(j-v-0.5))
        tail = min(N,math.floor(j+v+0.5))
        ans[head]+=1
        ans[tail+1]-=1
    A ,flg= calc(ans)
    if flg:
        A = [N]*N
print(*A)

Submission status: Wrong Answer

Solution code:
# tokiomarine2020_c.py
'''
imos 法を使って解くらしい
類題
https://atcoder.jp/contests/abc014/tasks/abc014_3
'''
import math
def calc(a):
    ret = []
    cumsum=0
    flg = True
    for i in a:
        cumsum+=i
        ret.append(cumsum)
        if cumsum<N:
            flg=False
    return  ret[:5],flg
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K):
    ans = [0]*(N+2)
    for j,v in enumerate(A):
        head = max(0,math.ceil(j-v-0.5))
        tail = min(N,math.floor(j+v+0.5))
        ans[head]+=1
        ans[tail+1]-=1
    A ,flg= calc(ans)
    if flg:
        break
print(*A)

Submission status: Wrong Answer

Solution code:
# tokiomarine2020_c.py
'''
imos 法を使って解くらしい
類題
https://atcoder.jp/contests/abc014/tasks/abc014_3
'''
import math
def calc(a):
    ret = []
    cumsum=0
    for i in a:
        cumsum+=i
        ret.append(cumsum)
    return  ret[:5]
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K):
    ans = [0]*(N+2)
    for j,v in enumerate(A):
        head = max(0,math.ceil(j-v-0.5))
        tail = min(N,math.floor(j+v+0.5))
        ans[head]+=1
        ans[tail+1]-=1
    A = calc(ans)
    if i>300:
        break
print(*A)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

for k in range(1,min(K+1,41)):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1,i+A[i])
        B[l] += 1
        if r+1 < N:
            B[r+1] -= 1
            
    for i in range(1,N):
        B[i] += B[i-1]
    A = B
print(*A)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(min(k, 20)):
    new_a = [0]*n
    for i in range(n):
        d = a[i]
        new_a[max(i-d, 0)] += 1
        if i+d+1 <= n-1:
            new_a[i+d+1] -= 1
    for i in range(n-1):
        new_a[i+1] += new_a[i]

    a = new_a

print(*a)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*(n+1)
tmp = [0]*(n+1)
tmp_sum = []
#print(ans)
#[0, 0, 0, 0, 0]

for kkk in range(300):
    #print(li,'li')
    for i,l in enumerate(li):
        if l != 0:
            start = max(0,i-l)
            end = min(n,i+l+1)
            #print(start,'start',end,'end')
            tmp[start] += 1
            #print(end,len(tmp),'aaa')
            tmp[end] -= 1
    #print(tmp,'tmp')
    last = 0
    for t in tmp:
        last = t+last
        tmp_sum.append(last)
    for i,l in enumerate(li):
        if l == 0:
            tmp_sum[i] += 1
    ans = tmp_sum[:n]
    li = tmp_sum[:n]
    tmp = [0]*(n+1)
    tmp_sum = []
    #if len(set(ans)) == 1:
    #    break
print(*ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*(n+1)
tmp = [0]*(n+1)
tmp_sum = []
#print(ans)
#[0, 0, 0, 0, 0]

for kkk in range(500):
    #print(li,'li')
    for i,l in enumerate(li):
        if l != 0:
            start = max(0,i-l)
            end = min(n,i+l+1)
            #print(start,'start',end,'end')
            tmp[start] += 1
            #print(end,len(tmp),'aaa')
            tmp[end] -= 1
    #print(tmp,'tmp')
    last = 0
    for t in tmp:
        last = t+last
        tmp_sum.append(last)
    for i,l in enumerate(li):
        if l == 0:
            tmp_sum[i] += 1
    ans = tmp_sum[:n]
    li = tmp_sum[:n]
    tmp = [0]*(n+1)
    tmp_sum = []
    #if len(set(ans)) == 1:
    #    break
print(*ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*(n+1)
tmp = [0]*(n+1)
tmp_sum = []
#print(ans)
#[0, 0, 0, 0, 0]

for kkk in range(200):
    #print(li,'li')
    for i,l in enumerate(li):
        if l != 0:
            start = max(0,i-l)
            end = min(n,i+l+1)
            #print(start,'start',end,'end')
            tmp[start] += 1
            #print(end,len(tmp),'aaa')
            tmp[end] -= 1
    #print(tmp,'tmp')
    last = 0
    for t in tmp:
        last = t+last
        tmp_sum.append(last)
    for i,l in enumerate(li):
        if l == 0:
            tmp_sum[i] += 1
    ans = tmp_sum[:n]
    li = tmp_sum[:n]
    tmp = [0]*(n+1)
    tmp_sum = []
    #if len(set(ans)) == 1:
    #    break
print(*ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*(n+1)
tmp = [0]*(n+1)
tmp_sum = []
#print(ans)
#[0, 0, 0, 0, 0]

for kkk in range(k):
    #print(li,'li')
    for i,l in enumerate(li):
        if l != 0:
            start = max(0,i-l)
            end = min(n,i+l+1)
            #print(start,'start',end,'end')
            tmp[start] += 1
            #print(end,len(tmp),'aaa')
            tmp[end] -= 1
    #print(tmp,'tmp')
    last = 0
    for t in tmp:
        last = t+last
        tmp_sum.append(last)
    for i,l in enumerate(li):
        if l == 0:
            tmp_sum[i] += 1
    ans = tmp_sum[:n]
    li = tmp_sum[:n]
    tmp = [0]*(n+1)
    tmp_sum = []
    if len(set(ans)) == 1:
        break
print(*ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [a for a in map(int, input().split())]

for _ in range(K):
    B = [0] * (len(A) + 1)
    for i in range(N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    for i in range(N):
        B[i] += B[i - 1]

    A = B[:-1].copy()

print(A)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [a for a in map(int, input().split())]
B = [0] * (len(A) + 1)

for i in range(N):
    l = max(0, i - A[i])
    r = min(N - 1, i + A[i])
    B[l] += 1
    if r + 1 < N:
        B[r + 1] -= 1

for i in range(N):
    B[i] += B[i - 1]

print(*B[:-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [a for a in map(int, input().split())]
B = [0] * (len(A) + 1)

for i in range(N):
    l = max(0, i - A[i])
    r = min(N - 1, i + A[i])
    B[l] += 1
    if r + 1 < N:
        B[r + 1] -= 1

for i in range(N):
    B[i] += B[i - 1]

print(B[:-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K):
    AA = [0] * N
    for j in range(len(A)):
        p = A[j]
        st = j - p if j - p >= 0 else 0
        ed = j + p if j + p < N else N - 1
        for k in range(st, ed+1):
            AA[k] += 1
    A = AA[:]
print(A)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A=[*map(int,input().split())]
for i in range(k):
    B = [0]*n
    for j in range(n):
        d = A[j] # 強さ
        l = max(0, j-d) # 範囲
        r = j+d+1 # 範囲
        B[l] += 1
        if r <= n-1: B[r] -= 1
    is_same = True
    for j in range(n-1):
        B[j+1] = B[j+1] + B[j]
        if B[j+1] != B[0]: is_same = False
    if is_same: break
    A = B
print(*B,sep=' ')

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A=[*map(int,input().split())]
m = min({19,k,n})
for i in range(m):
    B = [0]*n
    for j in range(n):
        d = A[j] # 強さ
        l = max(0, j-d) # 範囲
        r = j+d+1 # 範囲
        B[l] += 1
        if r <= n-1: B[r] -= 1
    for j in range(n-1):
        B[j+1] = B[j+1] + B[j]
    A = B
print(*B,sep=' ')

Submission status: Wrong Answer

Solution code:
import numpy as np
from numba import njit

N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
a = np.array(A, dtype=int)


fin = [N] * N

@njit(cache=True)
def calc_b(a):
    b = np.zeros(N, dtype=np.int64)
    for i, _a in enumerate(a):
        l = max(0, i - _a)
        r = min(N - 1, i + _a)


        for j in range(l,r+1):
            b[j]+=1

        # # imos hou
        # b[l] += 1
        # if r + 1 < N:
        #     b[r + 1] -= 1

    b = np.cumsum(b)
    # print('b_sum', b)
    return b


for k in range(min(K,100)):
    # print('a', a)
    a = calc_b(a)
    # if all(a == fin):
    #     break

a = [str(_) for _ in a]
print(' '.join(a))
# print('step=', k)

Submission status: Wrong Answer

Solution code:
import copy
N,K = map(int,input().split())
A = list(map(int,input().split()))

if K>20:
    ans = [str(N)]*N
    print(' '.join(ans))
    exit()

light = [0]*N
last_light = A
for j in range(K):
    for i in range(N):
        if i-last_light[i] < 0:
            start = 0
        else:
            start = i-last_light[i]
        if i+last_light[i] > N:
            last = N
        else:
            last = i+last_light[i]
        light = light[:start] + list(map(lambda x:x+1,light[start:last+1])) + light[last+1:]
    last_light = copy.copy(light)
    light = [0]*N

for i in range(N):
    last_light[i] = str(last_light[i])
print(' '.join(last_light))

Submission status: Wrong Answer

Solution code:
def right(a,n):
    sw = [0]*(n+1)
    for x,y in enumerate(a):
        x_min = max(0,x-y)
        x_max = min(n,x+y+1)
        sw[x_min] += 1
        sw[x_max] -= 1
    s = 0
    for i in range(n):
        s += sw[i]
        a[i] = s
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(min(k,30)):
    a = right(a,n)
a = [str(n) for n in a]
print(" ".join(a))

Submission status: Wrong Answer

Solution code:
def right(a,n):
    sw = [0]*(n+1)
    for x,y in enumerate(a):
        x_min = max(0,x-y)
        x_max = min(n,x+y+1)
        sw[x_min] += 1
        sw[x_max] -= 1
    s = 0
    for i in range(n):
        s += sw[i]
        a[i] = s
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(k):
    a = right(a,n)
    if sum(a) == n**2:
        break
print(a)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int, input().split()))
 
for _ in range(K):
  B = [0] * (N+1)
  for i in range(N):
    l = max(0, i-A[i])
    r = min(i+A[i]+1, N)
    B[l] += 1
    B[r] -= 1
 
  for i in range(N):
    B[i+1] += B[i]
 
  if all(b==N for b in B[:-1]): break
  A = B
 
for i in range(N):
  print(A[i])

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int, input().split()))

for _ in range(K):
  B = [0] * (N+1)
  for i,a in enumerate(A):
    l = max(0, i-a)
    r = min(i+a+1, N)
    B[l] += 1
    B[r] -= 1

  for i in range(N):
    B[i+1] += B[i]

  if all(b==N for b in B[:-1]): break
  A = B

for i in range(N):
  print(A[i])

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [0] * N

for k in range(50):
    for i in range(N):
        d = A[i]

        l = i - d

        if l < 0:
            l = 0

        r = min(i + d + 1, N)
        for j in range(l, r):
            B[j] += 1

    A = B
    B = [0] * N

print(" ".join([str(x) for x in A]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())

aa = list(map(int, input().split()))

from itertools import accumulate

aa

for _ in range(k):
    d = [0] * n

    for i, a in enumerate(aa):
        d[max(i-a, 0)] += 1
        end = i+1+a
        if end < n:
            d[end] -= 1

    d = list(accumulate(d))
    if aa == d:
        break
    aa = d

print(aa)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(K):
        arr = [0]*(N+1)
        for i, a in enumerate(A):
            left = max(0, i-a)
            right = min(N, i+a+1)
            arr[left] += 1
            arr[right] -= 1
        
        A = list(accumulate(arr[:-1]))
        if all(a == N for a in A):
           break

    print(*A[:-1], sep=" ")



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n, k, *A = map(int, open(0).read().split())
for _ in range(min(k, 99)):
    B = [0] * (n+1)
    for i in range(n):
        B[max(0, i-A[i])] += 1
        B[min(n, i+A[i]+1)] -= 1
    A = list(accumulate(B))[:n]
print(A)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
A = list(map(int, input().split()))

def f(X):
  L = [0] * len(X)
  for k in range(len(X)):
    for j in range(len(X)):
      if max(0,j-X[j]) <= k <= max(j+X[j],n-1):
        L[k] += 1
      else:
        pass
  return [L[i]+X[i] for i in range(len(X))]
   
X = A
for i in range(k):
  X = f(X)
  
P = [str(X[i]) for i in range(n)]
print(" ".join(P))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
B =[]
for i in range(N):
	B.append(0)
for p in range(K):
	for i in range(N):
		for j in range(1 +A[i]):
			if j == 0:
				B[i] +=  1
			else:
				if i - j>= 0:
					B[i-j] += 1
				if i + j < N:
					B[i+j] += 1
	for i in range(N):
		A[i] =B[i]
		B[i] = 0
	if min(A)+(K-p) >= N:
		for i in range(N):
			A[i] =N
		break        
    
print(A)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
B =[]
for i in range(N):
	B.append(0)
for dummy in range(K):
	for i in range(N):
		for j in range(1 +A[i]):
			if j == 0:
				B[i] +=  1
			else:
				if i - j>= 0:
					B[i-j] += 1
				if i + j < N:
					B[i+j] += 1
	for i in range(N):
		A[i] =B[i]
		B[i] = 0
print(A)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int, input().split())

A_list = np.array(list(map(int, input().split())))
#print(A_np)


for j in range(min(K,46)):
  new_A=np.zeros(N+1,dtype=np.int64)
  for i in range(N):
    #print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma]-=1

  A_list=np.cumsum(new_A)
  #if A_list[1:N+1])==N*N:
  #  break
    
#for i in range(1,N+1):
#  print(A_list[i],end=" ")
print(*A_list[:-1],sep=' ')

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int, input().split())

A_list = np.array([0]+list(map(int, input().split())))
#print(A_np)


for j in range(min(K,46)):
  new_A=np.zeros(N+2,dtype=np.int64)
  for i in range(1,N+1):
    #print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma+1]-=1

  A_list=np.cumsum(new_A)
  #if A_list[1:N+1])==N*N:
  #  break
    
#for i in range(1,N+1):
#  print(A_list[i],end=" ")
print(*A_list,sep=' ')

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

for i in range(min(math.ceil(math.log(N))+10, K)):
  B = [0] * N
  for n, A_n in enumerate(A):
    B_min = max(0, n-A_n)
    b_max = min(N-1, n+A_n)
    B[B_min] += 1
    if b_max+1 < N:
      B[b_max+1] -= 1
  
  sum = 0
  for n in range(len(A)):
    sum += B[n]
    A[n] = sum

print(" ".join(list(map(str, A))))