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


def read_input(trans=int):
    return list(map(trans, input().split()))


N, K = read_input()
A = np.array(read_input(), dtype="int")
coordinate = np.arange(1, N+1)

K = np.minimum(K, 41)

for _ in range(K):
    B = np.zeros(N, dtype="int")
    for i in range(N):
        end = np.minimum(coordinate[i]+A[i], N)
        start = np.maximum(coordinate[i]-A[i], 1)

        B[start-1] += 1
        if end < N:
            B[end] -= 1
    B = np.cumsum(B)
    A = B.copy()


for i in A:
    print(A, end="")
    print(" ")

# print(" ".join(map(str, A.tolist())))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
T=list(map(int,input().split()))
if K==0:
    print(T)
    exit()
 
if N<=50:
    L=[N]*N
    print(L)
if K>50:
    K=50
#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(N)] for i in range(K+1)]
 
for i in range(N):
    S[0][i]=T[i]
 
#print(S)
for i in range(K):
    for j in range(N):
        d=S[i][j]
        #print(d)
        A=max(j-d,0)
        B=min(j+d+1,N)
        for k in range(A,B):
            #print(k,max(j-d,0),min(j+d+1,K+1))
            S[i+1][k]+=1
 
 
#print(S[K])
 
Z=[str(a) for a in S[K]]
Z=" ".join(Z)
print(Z)

Submission status: Wrong Answer

Solution code:
import numpy as np


n, k = map(int, input().split())
A = [int(i) for i in input().split()]

ans = np.array([0]*n)
for i in range(100):
  ans = np.array([0]*n)
  if i == 0:
    prev = A    
  #print("prev", prev)
  for j in range(n):
      start = max(0, j - prev[j])
      end = min(n-1, j + prev[j])
      #print("start, end", start, end)
      #print(ans[start:end+1])
      ans[start:end+1] += 1
  #print(i, ans)
  prev = ans
  if all([a >= n for a in ans]):
    #print("break", ans)
    break
print(' '.join([str(a) for a in ans.tolist()]))

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
count = 0

for i in range(50):
  for j in range(n):
    for m in range(n):
      if a[m] >= abs(m-j):
        b[j] += 1
  a = b  
  b = [0]*n
print(*a)

Submission status: Wrong Answer

Solution code:
def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>30:
    a=[n]*n
    print(*a)
    exit()
for i in range(k):
    b=[0]*(n+1)
    for j in range(n):
        l,r=max(0,j-a[j]),min(n,j+a[j]+1)
        b[l]+=1
        b[r]-=1
    a=Csum(b)[1:-1]
print(*a)

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
count = 0

for i in range(100):
  for j in range(n):
    for m in range(n):
      if a[m] >= abs(m-j):
        b[j] += 1
  a = b  
  b = [0]*n
print(*a)

Submission status: Wrong Answer

Solution code:
def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>20:
    a=[n]*n
    print(*a)
    exit()
for i in range(k):
    b=[0]*(n+1)
    for j in range(n):
        l,r=max(0,j-a[j]),min(n,j+a[j]+1)
        b[l]+=1
        b[r]-=1
    a=Csum(b)[1:-1]
print(*a)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a_l = list(map(int,input().split()))
li_range = [[] for i in range(n)]

for i in range(n):
    li_range[i] = [i+1-a_l[i]-0.5,i+1+a_l[i]+0.5]

#ここまでででO(n)

for k in range(k):
    count_li = [0]*n
    for i in range(n):
        for j in range(n):
            if li_range[j][0]<i+1<li_range[j][1]:
                count_li[i]+=1
    for i in range(n):
        li_range[i] = [i+1-count_li[i]-0.5,i+1+count_li[i]+0.5]

print(count_li)

Submission status: Wrong Answer

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


for i in range(k):

    if i > math.log(n)+3:
        alist = [n] * n
        break
    new = [0] * n
    for j in range(n):
        distance = j - alist[j]
        if distance < 0:
            distance = 0
        last =  j + alist[j]
        if last > n-1:
            last = n-1
        new[distance]+=1
        if last+1 < n:
            new[last+1]-=1
    for j in range(1,n):
        new[j] += new[j-1]
    alist = new
print(*alist)

Submission status: Wrong Answer

Solution code:
import copy
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [1] * n
for _ in range(int(math.log(n))):
    for i in range(n):
        light = 0
        for j in range(n):
            if i < j:
                if (j - a[j] - 0.5) < i:
                    light += 1
            else:
                if (j + a[j] + 0.5) > i:
                    light += 1
        b[i] = light
    a = copy.deepcopy(b)
print(a)

Submission status: Wrong Answer

Solution code:
import numpy as np


def read_input(trans=int):
    return list(map(trans, input().split()))


N, K = read_input()
A = np.array(read_input(), dtype="int")
coordinate = np.arange(1, N+1)

K = np.maximum(K, 41)

for _ in range(K):
    B = np.zeros(N, dtype="int")
    for i in range(N):
        end = np.minimum(coordinate[i]+A[i], N)
        start = np.maximum(coordinate[i]-A[i], 1)
        
        B[start-1] += 1
        if end < N:
            B[end] -= 1
    B = np.cumsum(B)
    A = B.copy()


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

Submission status: Wrong Answer

Solution code:
import numpy as np

if __name__ == '__main__':
    N, K = map(int, input().strip().split(" "))
    A = np.array(input().strip().split(" ")).astype(int)

    if K >= 41 or N <= K:
        print(" ".join([str(N)] * N))
    else:
        if N > 30 and N/3 < K:
            print(" ".join([str(N)] * N))
        elif N > 20 and N/2 < K:
            print(" ".join([str(N)] * N))
        else:
            for i in range(K):
                B = np.zeros(N)
                for j in range(N):
                    for k in range(max(0, int(j - A[j])), min(int(j + A[j] + 1), N), 1):
                        B[k] += 1
                A = B.copy()
            print(" ".join(A.astype(str)))

Submission status: Wrong Answer

Solution code:
import copy
import sys

N,K=map(int,input().split())

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

for k in range(K):
    cl=[0]*N
    
    for i,d in enumerate(a_list):
        start=i-d
        end=i+d
        if start <0:
            start=0
        if end > N-1:
            end=N-1
        cl[start]+=1
        if end+1>N-1:
            pass
        else:
            cl[end+1]-=1
        
    d=0
    for i,c in enumerate(cl):
        d+=c
        a_list[i]=d
        
    if min(a_list) == N:
        print(cl)
        sys.exit(0)

for a in a_list:
    print(a,end=" ")

Submission status: Wrong Answer

Solution code:
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
# from numba import njit,i8


# @njit(i8[:](i8,i8,i8[:],i8,i8))
def loop(N,K,A,left,right):
    for j in range(K):
        B = np.zeros_like(A)
        for i in range(N):
            left = i - A[i]
            right = i + A[i] + 1
            if left < 0:
                left = 0
            if right > N:
                right = N
            B[left:right] += 1
        A = B
    return A


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

    if N >= 41:
        M = 41
    else:
        M = N

    res = loop(M,K,A,0,0)

    print(*res)



main()

Submission status: Wrong Answer

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


for i in range(k):

    if i > math.log(n):
        alist = [n] * n
        break
    new = [0] * n
    for j in range(n):
        distance = j - alist[j]
        if distance < 0:
            distance = 0
        last =  j + alist[j]
        if last > n-1:
            last = n-1
        new[distance]+=1
        if last+1 < n:
            new[last+1]-=1
    for j in range(1,n):
        new[j] += new[j-1]
    alist = new
print(*alist)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

if K > 40:
    K = 40

for k in range(K):
    B = np.zeros(N)
    for i in range(N):
        B[int(max(0, i - A[i])):int(min(i + A[i], N - 1))] += 1
    A = B

for a in A:
    print(int(a), end=" ")
print()

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

if K > 100:
    K = 100

for k in range(K):
    B = np.zeros(N)
    for i in range(N):
        B[int(max(0, i - A[i])):int(min(i + A[i], N - 1))] += 1
    A = B

for a in A:
    print(int(a), end=" ")
print()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*n
tmp = [0]*n
#print(ans)
#[0, 0, 0, 0, 0]
for kkk in range(50):
    for i,l in enumerate(li):
        for xx in range(n):
            sa = abs(xx - i)
            #print(sa,l,'sa',i)
            if sa<=l:
                tmp[xx]+=1
    ans = tmp
    li = tmp
    tmp = [0]*n
    if len(set(ans)) == 1:
        break
print(*ans)

Submission status: Wrong Answer

Solution code:
import copy
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [1] * n
for _ in range(42):
    for i in range(n):
        light = 0
        for j in range(n):
            if i < j:
                if (j - a[j] - 0.5) < i:
                    light += 1
            else:
                if (j + a[j] + 0.5) > i:
                    light += 1
        b[i] = light
    a = copy.deepcopy(b)
print(a)

Submission status: Wrong Answer

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

current_arr = A
for k in range(K):
    if k > 41:
        break
    next_arr = [0]*N
    for i, ai in enumerate(current_arr):
        for num in range(-ai, ai+1):
            ii = i + num
            if ii < 0 or N <= ii:
                continue
            next_arr[ii] += 1
    current_arr = next_arr
print(next_arr)

Submission status: Wrong Answer

Solution code:
import sys
# いもす法の利用
import copy 
N,K=map(int,(input().split()))
A=list(map(int,(input().split())))
B= [0 for _ in range(N)]
for i in range(K):
  B= [0 for _ in range(N)]
  C=0
  for j in A:

    if(C-j<0):
      left=0
      B[left]+=1
    else:
      left=C-j
      B[left]+=1
    if(C+j+1>=N):
      right=N-1
    else:
      right=C+j+1
      B[right]-=1

    C+=1
  if(C==100):
    reuseki = [N]*N
    print(*ruiseki)
    sys.exit()
    
  ruiseki = [0] * N  # 累積和用リスト
  ruiseki[0] = B[0]
  for m in range(N):
      ruiseki[m] = ruiseki[m-1] + B[m]
  A = copy.copy(ruiseki)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    on = [0 for _ in range(n+1)]
    for i in range(n):
        left = max(i - a[i], 0)
        right = min(i + a[i] + 1, n)
        on[left] += 1
        on[right] -= 1
    for j in range(1, n+1):
        on[j] += on[j-1] 
    if on.count(n) == n:
        break
    a = on[:]
print(*a[:n])

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for k in range(k):
    a_new = [0] * len(a)
    for i in range(n):

        b = list(range(int(i - a[i]), int(i + a[i] + 1)))
        for j in b:
            if j < 0 or j >= len(a):
                q = 0
            else:
                a_new[j] += 1
    a = a_new
    if len(list(set(a_new))) == 1:
        break

for i in a:
    print(int(i))

Submission status: Wrong Answer

Solution code:
import math

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

def shine(n,j):
  inf = math.ceil(max(j - n - 0.5,1))
  sup = math.floor(min(j + n + 0.5,N))
  return (inf - 1,sup - 1)

lim = min(50,K)

while lim > 0:
  tmp = [0] * N
  for i in range(0,N):
    ran = shine(light[i],i + 1)
    print(ran)
    for j in range(ran[0],ran[1] + 1):
      tmp[j] += 1
  light = tmp
  lim -= 1
    
print(light)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
if K >= 20:
    ans = [N]*N
    print(*ans)
else:
    for i in range(K):
        CA = [0]*N
        for j in range(N):
            CA[max(0,j-A[j]):min(j+A[j]+1,N)] = map(lambda x: x+1,CA[max(0,j-A[j]):min(j+A[j]+1,N)])
        A = [CA[i] for i in range(N)]
    print(*A)

Submission status: Wrong Answer

Solution code:
import copy
import sys

N,K=map(int,input().split())

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

for k in range(K):
    cl=[0]*N
    
    for i,d in enumerate(a_list):
        start=i-d
        end=i+d
        if start <0:
            start=0
        if end > N-1:
            end=N-1
        cl[start]+=1
        if end+1>N-1:
            pass
        else:
            cl[end+1]-=1
        
    d=0
    for i,c in enumerate(cl):
        d+=c
        a_list[i]=d
        
    if min(a_list) == N:
        sys.exit(0)

print(a_list)

Submission status: Wrong Answer

Solution code:
import copy
import numpy as np

def updaetAd(Ad, index, d, N):
    light_range =list(i for i in range(-d+index,d+index+1,1) if 0<=i<N)
    for j in light_range:
        if j >= 0 and j < N:
            Ad[j] += 1


def main():
    N, K = map(int,input().split(' '))
    A = np.array(list(map(int,input().split(' '))))
    for _ in range(41):
        Ad = np.array([0] * N)
        i = 0
        for a in A:
            updaetAd(Ad, i, a, N)
            i+=1

    ans = ''
    for i in A:
        ans += str(i) + ' '
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
if K >= 30:
    ans = [N]*N
    print(*ans)
else:
    for i in range(K):
        CA = [0]*N
        for j in range(N):
            CA[max(0,j-A[j]):min(j+A[j]+1,N)] = map(lambda x: x+1,CA[max(0,j-A[j]):min(j+A[j]+1,N)])
        A = [CA[i] for i in range(N)]
    print(*A)

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def f(N, K, A):
    p = 0
    for i in range(min(K, 100)):
        print(i)
        C = np.zeros(N + 1, dtype=np.int64)

        for j, a in enumerate(A):
            l = max(0, j - a)
            r = min(j + a + 1, N)
            C[l] += 1
            C[r] -= 1

        A = np.cumsum(C)

    return A


def solver():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A = f(N, K, A)
    print(*A[:-1])


solver()

Submission status: Wrong Answer

Solution code:
import math

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

def shine(n,j):
  inf = math.ceil(max(j - n - 0.5,1))
  sup = math.floor(min(j + n + 0.5,N))
  return (inf - 1,sup - 1)

lim = min(100,K)

while lim > 0:
  tmp = [0] * N
  for i in range(0,N):
    ran = shine(light[i],i + 1)
    print(ran)
    for j in range(ran[0],ran[1] + 1):
      tmp[j] += 1
  light = tmp
  lim -= 1
    
print(light)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
A=list(map(int, input().split()))
 
for k in range(K):
    L=[0]*N
    for i in range(N):
        for j in range(max(i-A[i],0),min(i+A[i],N)):
            L[i]+=1
        A=L
 
print(' '.join(map(str,A)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
rights = []
lefts = []
for i in range(41):
  for j in range(n):
    if j+a[j] < n-1:
      rights.append(j+a[j])
    if j-a[j] > 0:
      lefts.append(j-a[j])
  rights.sort()
  lefts.sort(reverse = True)
  a = [n]*n
  minus = 0
  for j in range(n):
    a[j] -= minus
    while rights != []:
      if rights[0] < j+1:
        minus += 1
        rights.pop(0)
      else:
        break
  minus = 0
  for j in reversed(range(n)):
    a[j] -= minus
    while lefts != []:
      if lefts[0] > j-1:
        minus += 1
        lefts.pop(0)
      else:
        break
        
for aa in a:
  print(str(aa) + " ", end = "")

Submission status: Wrong Answer

Solution code:
import copy
import sys

N,K=map(int,input().split())

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

for k in range(K):
    cl=[0]*N
    
    for i,d in enumerate(a_list):
        start=i-d
        end=i+d
        if start <0:
            start=0
        if end > N-1:
            end=N-1
        cl[start]+=1
        if end+1>N-1:
            pass
        else:
            cl[end+1]-=1
        
    d=0
    for i,c in enumerate(cl):
        d+=c
        a_list[i]=d
        
    if min(a_list) == N:
        print(cl)
        sys.exit(0)

print(a_list)

Submission status: Wrong Answer

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

for i in range(k):
    
    if i > math.log(n):
        map(lambda x:x+(k-i+1)*n, alist)
        break
    new = [0] * n
    for j in range(n):
        distance = j - alist[j]
        if distance < 0:
            distance = 0
        last =  j + alist[j]
        if last > n-1:
            last = n-1
        new[distance]+=1
        if last+1 < n:
            new[last+1]-=1
    for j in range(1,n):
        new[j] += new[j-1]
    alist = new
print(*alist)

Submission status: Wrong Answer

Solution code:
import collections

N,K = map(int,input().split())
FA = list(map(int,input().split()))
A = [0]*N
ANS = [N]*N
sm=[0]*N
la=[0]*N

for i in range(N):
    mi = max(0,i-FA[i])
    ma = min(N-1,i+FA[i])
    for i in range(mi,ma+1):
        A[i] +=1

if K==1:
    print(*A)
else:
    for i in range(N):
        sm[i] = max(0,i-A[i]-K+2)
        la[i] = min(N-1,i+A[i]+K-2)
    SM = collections.Counter(sm)
    LA = collections.Counter(la)

    SM = sorted(SM.items(),reverse=True)
    LA = sorted(LA.items())

    cnt=0
    jdex = 0
    for i in reversed(range(N)):
        ANS[i] -= cnt
        if(jdex!= len(SM) and i==SM[jdex][0]):
            cnt += SM[jdex][1]
            jdex += 1

    cnt=0
    jdex = 0
    for i in range(N):
        ANS[i] -= cnt
        if(jdex!= len(LA) and i==LA[jdex][0]):
            cnt += LA[jdex][1]
            jdex += 1

    print(*ANS)

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
    for i in range(n):
        left = max(0, i - a[i])
        right = min(n-1, i + a[i])
        b[left] += 1
        if right + 1 < n: 
            b[right + 1] -= 1

    a[0] = b[0]
    for i in range(1, n):
        b[i] += b[i-1]
        a[i] = b[i]
    
    if k >= 100:
        break

print(*a)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = np.asarray(A).astype(np.int)
C = np.arange(N).astype(np.int)

for i in range(K):
    _A = np.zeros((N,)).astype(np.int)

    maxs = A + C
    mins = C - A

    maxs = np.sort(maxs)
    mins = np.sort(mins)
    print(maxs)
    print(mins)

    cnt = 0
    f = 0
    for j in range(N):
        if mins[j] > cnt:
            _A[N - mins[j]:N-j] += f
            cnt = mins[j]
            f = 0
        else:
            f += 1
    _A[cnt:mins[j]] = f
    print(_A)

    cnt = 0
    f = 0
    for j in range(N):
        if maxs[j] > cnt:
            _A[N - maxs[j]:N-j] += f
            cnt = maxs[j]
            f = 0
        else:
            f += 1
    _A[cnt:mins[j]] = f
    print(_A)

    A = _A

    if np.all(A == N):
        break

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math

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

lamp = {}
for i in range(1, N+1):
    lamp[i] = A[i-1]

K = math.ceil(math.sqrt(K))

for k in range(K):
    lamp_next = defaultdict(lambda: 0)
    for i in range(1, N+1):
        l = i - lamp[i]
        if l < 1:
            l = 1
        r = i + lamp[i]
        if r > N:
            r = N
        for j in range(l, r+1):
            lamp_next[j] += 1
    lamp = lamp_next

ans = [lamp[i] for i in range(1, N+1)]
print(*ans)

Submission status: Wrong Answer

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

for i in range(k):
    
    if i > math.log(n):
        map(lambda x:x+(k-i-1)*n, alist)
        break
    new = [0] * n
    for j in range(n):
        distance = j - alist[j]
        if distance < 0:
            distance = 0
        last =  j + alist[j]
        if last > n-1:
            last = n-1
        new[distance]+=1
        if last+1 < n:
            new[last+1]-=1
    for j in range(1,n):
        new[j] += new[j-1]
    alist = new
print(*alist)

Submission status: Wrong Answer

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

for i in range(K):
    B = [0] * N
    for i in range(N):
        d = A[i]
        B[i] += 1
        for j in range(d):
            if i + j+1 < N:
                B[i + j+1] += 1
            if i > j:
                B[i - j - 1] += 1
    for i in range(N):
        A[i] = B[i]


print(A)

Submission status: Wrong Answer

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

if k >= n:
    for i in range(n-1):
        print(n, end=" ")
    print(n)
    exit()

for _ in range(k):
    list = [1]*n
    for i, d in enumerate(a):
        tmp = [0]*(i-d) + [1]*(2*d+1) + [0]*(n-i-d-1)
        list += tmp
    a = list.copy()
    if _ > 3000:
        break
for i in range(n-1):
    print(a[i], end=" ")
print(a[-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
import math 

n, k = map(int, input().split())
A = [int(i) for i in input().split()]

ans = np.array([0]*n)
for i in range(int(math.log(n))+1):
  ans = np.array([0]*n)
  if i == 0:
    prev = A    
  #print("prev", prev)
  for j in range(n):
      start = max(0, j - prev[j])
      end = min(n-1, j + prev[j])
      #print("start, end", start, end)
      #print(ans[start:end+1])
      ans[start:end+1] += 1
  #print(i, ans)
  prev = ans
  if all([a >= n for a in ans]):
    #print("break", ans)
    break
print(' '.join([str(a) for a in ans.tolist()]))

Submission status: Wrong Answer

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

for i in range(500):
    ans=[0]*(n)
    for j in range(n):
        l=max(0,j-a[j])
        r=j+1+a[j]
        ans[l]+=1
        if r<n:
            ans[r]-=1
    for z in range(n-1):
        ans[z+1]+=ans[z]
    a=ans
print(" ".join(list(map(str,ans))))

Submission status: Wrong Answer

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

if K > math.log2(N):
    for _ in range(N):
        print(N," ", end = "")
    print()
else:
    for i in range(K):
        cum_sum = [0]*N
        for j in range(N):
            left = max(0, j - A[j])
            right = min(N-1, j+A[j])
            cum_sum[left] += 1
            if right + 1 < N:
                cum_sum[right+1] -= 1
        
        A[0] = cum_sum[0]
        for j in range(N-1):
            cum_sum[j+1] += cum_sum[j]
            A[j+1] = cum_sum[j+1]
        
    for i in range(N):
        print(A[i], " ", end = "")
    print()

Submission status: Wrong Answer

Solution code:
from math import log2
def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(int(log2(K))+1):
        B = [0]*N
        for j in range(N):
            l = max(0,j-A[j])
            r = min(N-1,j+A[j])
            B[l:r+1] = map(lambda x:x+1, B[l:r+1])
        A = B
    print(*A)

main()

Submission status: Wrong Answer

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

def hantei(a):
    for i in range(n):
        if a[i] != n:
            return False
    return True

for _ in range(42):
    temp = [0]*n
    for i in range(n):
        start,goal = i-a[i], i+a[i]+1
        for j in range(i-a[i],i+a[i]+1):
            if 0<=j<n:
                temp[j]+=1
    a=temp[:]
    if hantei(a):
        break

for val in a:
    print(val, end=" ")

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int, input().split())
if K >= 1000 and N / 2 + 1 < K:
    K = int(math.sqrt(N))
A_list = list(map(int, input().split()))

A_New_list = [0 for i in range(N)]
for k in range(1000):
    for i in range(N):
        for j in range(A_list[i] + 1):
            if j == 0:
                # if A_list[i] != 0:
                A_New_list[i] += 1
            else:
                if i + j < N:
                    A_New_list[i+j] += 1
                if i - j >= 0:
                    A_New_list[i-j] += 1
    # print(A_New_list)
    A_list = A_New_list
    if k != K - 1:
        A_New_list = [0 for n in range(N)]
A_New_list = [str(a) for a in A_New_list]
ans = " ".join(A_New_list)
print(ans)

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(n):
    l = max(0, i-a[i])
    r = min(n, i+a[i]+1)
    b[l] += 1
    if r < n:
      b[r] -= 1
  for i in range(1, n): 
    b[i]+=b[i-1]
  a = b

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

Submission status: Wrong Answer

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

for i in range(k):
    
    if i > math.log(n):
        map(lambda x:x+(k-i)*n, alist)
        break
    new = [0] * n
    for j in range(n):
        distance = j - alist[j]
        if distance < 0:
            distance = 0
        last =  j + alist[j]
        if last > n-1:
            last = n-1
        new[distance]+=1
        if last+1 < n:
            new[last+1]-=1
    for j in range(1,n):
        new[j] += new[j-1]
    alist = new
print(*alist)

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N,K = LI()
    a = LI()

    for _ in range(K):
        x = [0] * N
        for i in range(N):
            s = i - a[i]
            if s < 0: s = 0
            x[s] += 1
            t = i + a[i] + 1
            if t < N:
                x[t] -= 1
        a = []
        cnt = 0
        finish = False
        for i in range(N):
            cnt += x[i]
            if cnt == N: finish = True
            a.append(cnt)
        if finish: break
    print(*a,sep=' ')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(50):
    ans=[0]*(n)
    for j in range(n):
        l=max(0,j-a[j])
        r=j+1+a[j]
        ans[l]+=1
        if r<n:
            ans[r]-=1
    for z in range(n-1):
        ans[z+1]+=ans[z]
    a=ans
print(" ".join(list(map(str,ans))))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import math
if K >= 6+math.log2(N):
    A = [N]*N
else:
    for _ in range(K):
        B = A
        C = [0]*N
        for i in range(N):
            b = B[i]
            l, r = max(0, i-b), min(N-1, i+b)
            C[l] += 1
            if r != N-1:
                C[r+1] -= 1
        A[0] = C[0]
        for i in range(1,N):
            A[i] = A[i-1] + C[i]
print(' '.join(map(str, list(map(int, A)))))

Submission status: Wrong Answer

Solution code:
import sys
import math
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
imos = list(map(int, ("0 " + input()).split()))
logn = int(math.log(n)) + 1
# print(logk)
for ii in range(min(k, logn)):
    ans = [0 for _ in range(n + 1)]
    for i in range(1, n + 1):
        left = max(1, i - imos[i])
        # right = min(n, i + imos[i])
        ans[left] += 1
        if i + imos[i] + 1 <= n:
            ans[i + imos[i] + 1] -= 1
    now = 0
    for i in range(len(ans)):
        now += ans[i]
        imos[i] = now

# print(imos)
for i in imos[1:]:
    print(i)

# print(ans)

Submission status: Wrong Answer

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

for i in range(50):
    ans=[0]*(n)
    for j in range(n):
        l=max(0,j-a[j])
        r=j+1+a[j]
        ans[l]+=1
        if r<n:
            ans[r]-=1
    for z in range(n-1):
        ans[z+1]+=ans[z]
    a=ans
    if ans[0]==n and ans[n-1]==0:
        print(" ".join(list(map(str,ans))))
        sys.exit()
print(" ".join(list(map(str,ans))))

Submission status: Wrong Answer

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

K = max(K,50)
for k in range(K):
  light = [0] * N
  for i in range(N):
    start = max(0,i-A[i])
    end = min(N-1, i+A[i])
    for j in range(start, end+1):
      light[j] += 1
    
  A = light

print(" ".join(map(str,light)))

Submission status: Wrong Answer

Solution code:
import math

def action(A, N):
  B = [0] * N
  for i in range(N):
    s = max(0, math.ceil(i - A[i] - 0.5))
    e = min(N, math.ceil(i + A[i] + 0.5))
    for j in range(s, e):
      B[j] += 1 
  return B

def main():
  N, K = map(int, input().split())
  A = [int(s) for s in input().split()]

  for i in range(41):
    A = action(A, N)
      
  print(A)

if __name__ == '__main__':
  main()