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: Time Limit Exceeded

Solution code:
import numpy as np

N, K = [int(x) for x in input().split()]
lamp_list = np.array(list(map(int, input().split())))

for x in range(K):
    light = np.array([0 for x in range(N)])
    for i, lamp_power in enumerate(lamp_list):
        lower = i - lamp_power
        if lower < 0:
            lower = 0
        higher = i + lamp_power + 1
        if higher > N:
            higher = N
        # print(f"lower:{lower} high:{higher}")
        for j in range(lower, higher):
            light[j] += 1
        # print(f"i:{i} pow{lamp_power}")
        # print(light)
    lamp_list = light

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

Submission status: Time Limit Exceeded

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

als = [[0, 0] for _ in range(n)]

for i in range(n):
    if i - a[i] >= 0:
        als[i][0] = i-a[i]
    else:
        als[i][0] = 0
    if i + a[i] < n:
        als[i][1] = i+a[i]
    else:
        als[i][1] = n-1

for _ in range(k):
    mina = 1000000
    a = [0 for _ in range(n)]
    for j in range(n):
        for t in range(als[j][0], als[j][1]+1, 1):
            a[t] += 1
    for j in range(n):
        if mina > a[j]:
            mina = a[j]
    if a[j] >= n:
        break
    als = [[0, 0] for _ in range(n)]
    for i in range(n):
        if i - a[i] >= 0:
            als[i][0] = i-a[i]
        else:
            als[i][0] = 0
        if i + a[i] < n:
            als[i][1] = i+a[i]
        else:
            als[i][1] = n-1 

ans = ""

for i in range(n):
    ans += str(a[i]) + " "

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(k):
    W = [0] * n
    for j in range(n):
        area = A[j]
        for place in range(max(j-area ,0), min(j+area + 1, n)):
            W[place] += 1
    A = W
    if min(W) == n:
        break
W_list = map(str, W)
print(" ".join(W_list))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
li_A=list(map(int,input().split()))
import copy
li_B=copy.deepcopy(li_A)
def abs(n):
    if n<0:
        n*=-1
    return(n)
#次の操作をk回繰り返す
for i in range(k):
    li=[]
    #次の操作をn個の電球に対し行う
    for s in range(n):
        #s番目を照らす電球がある座標をliに入れていく
        for t in range(n):
            #t番目の電球がs番目を照らすかチェック
            if li_A[t]>=abs(t-s):
                li.append(t)
        #照らされている座標の電球の明るさを変える
        li_B[s]=len(li)
        li=[]
    li_A=copy.deepcopy(li_B)
li_B=list(map(str,li_B))
li_B=' '.join(li_B)
print(li_B)

Submission status: Time Limit Exceeded

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

for k in range(K):
    flag_all = True
    for i in range(N):
        if A[i] != N:
            flag_all = False
    if flag_all:
        break

    B = [0] * N
    for i in range(N):
        d = A[i]
        for j in range(-d, d+1):
            index = i + j
            if 0 <= index < N:
                B[index] += 1
    A = B
print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

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(K):
        Ad = np.array([0] * N)
        i = 0
        for a in A:
            updaetAd(Ad, i, a, N)
            i+=1
        if (A == Ad).all(): break
        A = copy.copy(Ad)

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

a_tmp = [0] * n
a_range = []*n
#print(a_tmp)

for i in range(k):
    for x in range(n):
        # まずは一つ目が照らしている電球を考える
        # 範囲は式通り
        left = math.ceil(x - a_array[x] - 0.5)
        if left < 0:
            left = 0
        right  = math.floor(x + a_array[x] + 0.5)
        if right > n - 1:
            right = n -1
        a_tmp = [a_tmp[i]+1 if (i>=left and i<right+1) else a_tmp[i] for i in range(0, n)]

        #for j in range(left, right+1):
            #a_tmp[j] += 1
        
        #print(a_tmp)
    a_array = a_tmp
    a_tmp = [0]*n

ans = " ".join(map(str, a_array))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())
A = list(map(int, input().split()))
end = [N] * N

for _ in range(K):
    lst = [0] * N
    for i, a in enumerate(A):
        lst[max(0, i - a)] += 1
        if i + a + 1 < N:
            lst[i + a + 1] -= 1
    A = list(itertools.accumulate(lst))
    if A == end:
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = np.asarray(a, dtype=int)
check = 0
for i in range(k):
    count = 0
    b = np.zeros(n, dtype=int)
    for j in range(n):
        if a[j]>0:
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            if ma==n-1 and mi==0:
                count+=1
            for k in range(mi,ma+1):
                b[k]+=1
        else:
            b[j]+=1
    if count==n:
        check = i
        break
    a = b
if check!=0:
    for i in range(n):
        a[i]+=k-check
print(*a)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
if N==1:
    print(1)
    exit()
if K >= N-1:
    for i in range(N-1):
        print(N,end=" ")
    print(N)
    exit()

for k in range(K):
    nextgen = [0]*N
    for i in range(N):
        # print("i=",i)
        a = A[i]
        start = i-a
        if i-a <0:
            start = 0
        end = i+a+1
        if i+a+1 <=N-1:
            nextgen[end] += -1
            end = N-1
        # print(start,end)
        nextgen[start] += 1
        # print(nextgen)
    dp = 0
    for i in range(N):
        dp += nextgen[i]
        A[i] = dp
    if A == [N]*(N):
        break
s = ' '.join([str(i) for i in A])
print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K=map(int,input().split())
a=input().split()
A=[int(b) for b in a]
A=np.array(A)
suuji=0
for k in range(K):
    a = [1 for _ in range(N)]
    for n in range(N):
        a=np.array(a)
        number=A[n]
        plus=n+number
        minus=n-number
        if minus<0:
            minus=0
        a[minus:n]+=1
        a[n+1:plus+1]+=1
    A=a
    if sum(A)==N**2:
        break
    suuji+=1
answer=''
for a in A:
    answer+=str(a)
    answer+=' '
print(answer)

Submission status: Time Limit Exceeded

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


def calc_imos(arr):
    imos = [0] * (N + 1)
    for i, a in enumerate(arr):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        imos[l] += 1
        imos[r + 1] -= 1
    imos = list(accumulate(imos))
    return imos[:-1]


for k in range(min(1000, K)):
    A = calc_imos(A)
print(*A, sep=' ')

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
def LI():return list(map(int,input().split()))
def yes():print("YES")
def no():print("NO")

n,k=LI()
a=LI()

if k>10**4 or k>=n:
    ans=[n]*n
    print(*ans)
    exit()


for _ in range(k):
    b=[0]*n
    for i in range(n):
        q=a[i]
        for j in range(i-q,i+q+1):
            if 0<=j<=n-1:
                b[j]+=1
    a=b[:]
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import copy
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0]*N
for i in range(K):
    for j in range(N):
        g = math.ceil(j+1-A[j]-0.5)
        if g<1:
            g=1
        h = math.floor(j+1+A[j]+0.5)
        if h>N:
            h=N
        for x in range(g,h+1):
            A2[x-1]+=1
    A=copy.copy(A2)
    A2 = [0]*N

print(*A)

Submission status: Time Limit Exceeded

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

max_power = [n for i in range(n)]
init_light = [0 for i in range(n)]
for i in range(k):
  number_light = init_light
  for j,_power in enumerate(light_power):
    if _power == 0:
      number_light[j] += 1
    else:
      number_light = list(map(sum, zip(number_light, [1 if i>=(j+1-_power-0.5) and (j+1+_power+0.5)>=i else 0 for i in range(1,n+1)])))
  light_power = number_light
  if light_power == max_power:
    break
print(' '.join(map(str, light_power)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, K = map(int, input().split())
    a = list(map(int, input().split()))
    cnt = a.count(n)
    for k in range(K):
        an = [0] * n
        for i in range(n):
            if an[i] < n:
                an[i] += 1
            for j in range(1, a[i]+1):
                if i - j >= 0 and an[i-j] < n:
                    an[i-j] += 1
                    if an[i-j] == n:
                        cnt += 1
                if i + j < n and an[i+j] < n:
                    an[i+j] += 1
                    if an[i+j] == n:
                        cnt += 1
        else:
            a = an
            if cnt == n:
                break
    print(*a)
main()

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
import sys
# import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


n, k = xnxn()
a = xnxn(flag="l")
for _ in range(k):
    add = [0]*n
    for i in range(0, n):
        idx_min = max(0, i - a[i])
        idx_max = min(n-1, i + a[i])
        for t in range(idx_min, idx_max + 1):
            add[t] = add[t]+1
    a = add

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

Submission status: Time Limit Exceeded

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

l = min(A)


for _ in range(int(K/2)):
    T = [0]*N
    for i in range(N):
        for j in range(max(0,i-A[i]), min(N-1, i+A[i])+1):
            T[j] += 1
    A, T = T, A

    T = [0]*N
    for i in range(N):
        for j in range(max(0,i-A[i]), min(N-1, i+A[i])+1):
            T[j] += 1
    A, T = T, A

if K%2 == 1:
    T = [0]*N
    for i in range(N):
        for j in range(max(0,i-A[i]), min(N-1, i+A[i])+1):
            T[j] += 1
    A, T = T, A



print(*A)

Submission status: Time Limit Exceeded

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

def updateAi(Ai):
  newAi = [1 for _ in range(N)]
  for i in range(N):
    for j in range( max(-1*Ai[i],-1*i),min(Ai[i]+1, N-i)):
      #print('j = '+str(j))
      if(j!=0):
        newAi[i+j] += 1
    ###newAi[max(-1*Ai[i],-1*i)+i:min(Ai[i], N-i-1)+i] += [1 for _ in range(2*Ai[i]+1)]
    ###newAi[i] -= 1
    #print('newAi at '+str(i)+' = '+str(newAi))
  
  return newAi

#newAi = [1 for _ in range(N)]
for _ in range(K):
  #Ai = updateAi(Ai)
  newAi = [1 for _ in range(N)]
  for i in range(N):
    for j in range( max(-1*Ai[i],-1*i),min(Ai[i]+1, N-i)):
      #print('j = '+str(j))
      if(j!=0):
        newAi[i+j] += 1
  Ai = newAi
#print(Ai)
L=[str(Ai) for Ai in Ai]
L=" ".join(L)
print(L)

Submission status: Time Limit Exceeded

Solution code:
def C():
    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    pre = {}
    for i in range(n):
        pre[i+1] = a[i]
    import collections
    for _ in range(k):
        tmp = []
        for i in range(n):
            x_min = 1 if (i+1)-pre[(i+1)] < 1 else (i+1)-pre[(i+1)]
            x_max = n if (i+1)+pre[(i+1)] > n else (i+1)+pre[(i+1)]
            tmp.extend(range(x_min,x_max+1))
        pre = collections.Counter(tmp)
    s = ""
    for i in range(1,n+1):
        if s != "":
            s += " "
        if i not in pre:
            s += str(0)
        else:
            s += str(pre[i])
    print(s)
C()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(k):
    tmp = np.array([0] * n, dtype="i8")
    mn = a[0]
    for x, y in enumerate(a):
        tmp[max(0, x - y):min(x + y + 1, n)] += 1
        if mn > y:
            mn = y
    a = tmp
    if mn >= n:
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for kk in range(k):
  b = []
  for i,j in enumerate(a):
    il, ir = i, i
    sl, sr = 1, 1
    bi = 1
    while il != 0:
      il -= 1
      if a[il] >= sl:
        bi += 1
      sl += 1
    while ir != n-1:
      ir += 1
      if a[ir] >= sr:
        bi += 1
      sr += 1
    b.append(bi)
  a = b
print(*b)

Submission status: Time Limit Exceeded

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

# for i in range(n):
#     b[i][i] = 1
#     print(b[i])

for i in range(k):
    for j in range(n):
        # print(b[j])
        for l in range(n):
            if b[j][l] == 0 and abs(j - l) <= a[l] + 0.5:
                b[j][l] = 1
        # print(b[j])
    for j in range(n):
        a[j] = b[j].count(1)

ans = ""
for i in range(n):
    ans += str(a[i]) + " "

print(ans[: 2 * n - 1])

Submission status: Time Limit Exceeded

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

A = list(map(int,input().split()))
flg = False
for i in range(K):
    B = [0]*N
    for j in range(N):
        if i > 0 and A[0] == N:
            flg = True
            break
        if A[j] > 0:
            start = j - A[j]
            stop = j + A[j] + 1
            if start < 0:
                start = 0
            if stop > N:
                stop = N
            for k in range(start,stop):
                    B[k] += 1
        else:
            B[j] += 1
    if flg:
        break
    A = B

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = [int(s) for s in input().split()]
b = a[:]
m=0
for e in range(0, k):
	for i in range(0, n):
		for j in range(0, n):
			if i>j:
				l=i-j
			elif j>i:
				l=j-i
			elif i==j:
				l=0

			if a[j]-l>=0:
				m=m+1

		b[i]=m
		m=0
	for u in range(0, n):
		a[u]=b[u]
ax=[str(w) for w in a]
ax = ' '.join(ax)
print(ax)

Submission status: Time Limit Exceeded

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

for i in range(K):
    # j番目の電球を操作
    B = [0] * N
    for j in range(N):
        maxA = int(j + A[j] + 0.5)
        minA = math.ceil(j - A[j] - 0.5)

        for k in range(max(0, minA), min(N, maxA + 1)):
            B[k] += 1
    A = copy.copy(B)

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

Submission status: Time Limit Exceeded

Solution code:
num_bulb, count = map(lambda x: int(x), input().split())
brightness = list(map(lambda x: int(x), input().split()))

for i in range(count):
    next_brightness = [0] * num_bulb
    # それぞれの電球について
    for j in range(num_bulb):
      for lighted_i in range(max(0, j - brightness[j]), min(num_bulb, j + brightness[j] + 1)):
            next_brightness[lighted_i] += 1
    brightness = next_brightness

print(' '.join(list(map(lambda x: str(x), next_brightness))))

Submission status: Time Limit Exceeded

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

def henkan(A,N):
    ANS=[0]*N
    for i in range(N):
        ANS[i]+=1
        for j in range(1,A[i]+1):
            if i+j<=N-1:
                ANS[i+j]+=1
            else:
                break
        for k in range(1,A[i]+1):
            if i-k>=0:
                ANS[i-k]+=1
            else:
                break
    return ANS

for i in range(K):
    A=henkan(A,N)
    if A==[N]*N:
        print(*A)
        exit()
    else:
        pass
print(*A)

Submission status: Time Limit Exceeded

Solution code:
N,K= map(int,input().split())
A = list(map(int,input().split()))
T = [0]*N
for t in range(K):
    for i in range(N):
        for j in range(i-A[i],i+A[i]+1):
            if j>=0 and j<=N-1:
                T[j] += 1
    A = T
    T =[0]*N
A=' '.join(map(str,A))
print(A)

Submission status: Time Limit Exceeded

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

    max_N = [N]*N

    for k in range(K):
        illumi = [0] * N
        i = 0
        for i in range(N):
            l = A[i]
            for j in range(max(0, i - l), min(N, i + l + 1)):
                illumi[j] += 1

        if (illumi == max_N):
            break

        A = [i for i in illumi]

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import itertools
from collections import deque
import numpy as np

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    num=np.array([0]*N)
    for i in range(K):
        num=[0]*N
        for n in range(N):
            s = n-A[n] if n-A[n]>=0 else 0
            e = n+A[n]+1 if n+A[n]+1 <= N else N
            # for m in range(s,e):
            #     # print(m)
            #     num[m]+=1
            num[s:e]+=np.array([1]*(e-s))
        # for n in range(N):

        A=num

    # print(A[])
    print(' '.join([str(a) for a in A]))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(k):
    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: Time Limit Exceeded

Solution code:
import collections

n, K = map(int, input().split())
a = [int(i) for i in input().split()]

for k in range(K):
    change_list = []
    for i in range(n):
        d = a[i]
        change = [j for j in range(1,n+1) if i+1-d-0.5 < j < i+1+d+0.5]
        change_list.extend(change)
    counter = collections.Counter(change_list)
    for m in range(n):
        a[m] = counter[m+1]

ans_list = [str(c) for c in a]
ans=' '.join(ans_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
input_list = list(map(int, input().split()))

for i in range(K):
    if input_list == [N for i in range(N)]:
        break

    tmp_list = [1 for i in range(N)]
    for j in range(N):
        for l in range(input_list[j]):
            if 0 <= j-l-1:
                tmp_list[j-l-1] = tmp_list[j-l-1]+1
            if j+l+1 <= N-1:
                tmp_list[j+l+1] = tmp_list[j+l+1]+1
        #print(tmp_list)

    input_list = tmp_list

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

Submission status: Time Limit Exceeded

Solution code:
import math

n, k = map(int, input().split())
li_light = list(map(int, input().split()))

def func(tuyosa):
  basho = []
  # 光が当たっている部分
  for i in range(len(tuyosa)):
    min = math.ceil(i + 1 - tuyosa[i] - 0.5)
    max = i + 1 + tuyosa[i] + 0.5
    add_list = []
    a = 0
    while a <= n:
      add_list.append(min)
      min += 1
      if min > max:
        break
    for j in add_list:
      basho.append(j)
   # 次の強さ
  tuyosa_ = []
  for k in range(len(tuyosa)):
    tuyosa_.append(basho.count(k + 1))
  return tuyosa_

for i in range(k):
  li_light = (func(li_light))

for k in li_light:
  print(k, end=" ")

Submission status: Time Limit Exceeded

Solution code:
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
if k >= len(ls):
    for q in range(len(ls)):
        print(len(ls),end=" ")
    sys.exit()
for _ in range(k):
    new = [0]*n
    for i in range(n):
        p = 0
        for l in range(1,max(n-i,i+1)):
            if i+l >= 0 and i+l <n:
                if ls[i+l] >= l:
                    p += 1
            if i-l >= 0 and i-l <n:
                if ls[i-l] >= l:
                    p += 1
        new[i] = p+1
    ls = new
for p in ls:
    print(p,end=" ")

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

def mi():
    return map(int, input().split())

def BIT_query(idx, BIT):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def main():
    N, K = mi()
    A = list(mi())

    for _ in range(K):
        l = [0]*N
        for i in range(N):
            left = max(i-A[i], 0)
            right = min(i+A[i]+1, N)
            l[left] += 1
            if right < N:
                l[right] -= 1
        A = list(accumulate(l))
    print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = input().split()
i_list = list(range(len(a)))
a = [int(a[i]) for i in i_list]
c = [0]*n
for m in range(k):
    for i in range(n):
        b = [a[j]-abs(j-i) for j in i_list]
        c[i] = sum(1 for x in b if x >=0)
    a = []
    a += c
a = [str(aa) for aa in a]
print(' '.join(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, K = map(int, input().split())
A_list = np.array(list(map(int, input().split())))
Base = np.ones(N, dtype=np.int64)

for _ in range(K):
    e_list_1 = np.zeros(N,dtype=np.int64)
    l_1 = np.zeros(N,dtype=np.int64)
    v = 0
    for i,a in enumerate(A_list):
        l_1[i] = v 
        e_list_1[min(i + a, N-1)] += 1
        v = v + 1 - e_list_1[i]
    
    e_list_2 = np.zeros(N,dtype=np.int64)
    l_2 = np.zeros(N,dtype=np.int64)
    v = 0
    for _i,a in enumerate(A_list[::-1]):
        i = N-1-_i
        l_2[i] = v
        e_list_2[max(i-a, 0)] += 1
        v = v + 1 - e_list_2[i]
    
    A_list = l_1 + l_2 + Base
print(*A_list)

Submission status: Time Limit Exceeded

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


for j in range(1,k+1):  #繰り返し
    bi = []
    for i in range(1,n+1):  #i番目の電球
        c = 0
        for h in range(1,n+1): #h番目の電球から光がとどいているか
            if abs(i - h) <= ai[h-1]:
                c += 1
        bi.append(c)
    ai = bi

ci=[str(a) for a in ai]
ci=' '.join(ci)
print(ci)

Submission status: Time Limit Exceeded

Solution code:
import sys

class ConsoleOut(object):
    def __lshift__(self, message):  # Left Shift(<<)演算子の処理を定義
        sys.stdout.write(str(message))
        return self

cout = ConsoleOut()

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

ANS = [0 for n in range(N)]

for k in range(K):
  S = [0 for n in range(N)]
  for i in range(N):
    start = i - A[i]
    end = i + A[i] + 1
    if start < 0:
      start = 0
    if end > N:
      end = N
    for j in range(start, end):
      S[j] += 1
  ANS = [ANS[l]+S[l] for l in range(N)]
  A = S
for i in range(N):
  cout << S[i] << " "
cout << "\n"

Submission status: Time Limit Exceeded

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

for i in range(K):
    Ad = [1]*N
    for j in list(np.nonzero(A)[0]):
    # for j in range(N):
        for k in range(A[j]):
            if j-k-1>=0:
                Ad[j-k-1]+=1
            if j+k+1<N:
                Ad[j+k+1]+=1
    A = Ad

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

Submission status: Time Limit Exceeded

Solution code:
import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush
import collections

n,k=list(map(int,stdin.readline().split()))
a=list(map(int,stdin.readline().split()))


for i in range(k):
    #nw=[0]*n
    pr=[0]*n
    for x,d in enumerate(a):
        if d==0:
            pr[x]+=1
            if x!=n-1:
                pr[x+1]-=1
            continue
        l=math.floor(x-d)
        r=math.floor(x+d)
        l=max(0,l)
        r=min(n-1,r)
        pr[l]+=1
        if r!=n-1:
            pr[r+1]-=1
    
    for m in range(1,n):
        pr[m]+=pr[m-1]
    
    a[:]=pr


        

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, k = map(int, input().split())
a_list = np.array(list(map(int, input().split())))

for ki in range(k):
  b_list = np.array([0] * n)
  for i, ai in enumerate(a_list):
    b_list += np.array([0]*max(0,i-ai) + [1]*(n-max(0,i-ai)-max(0,n-(i+1+ai))) + [0]*max(0,n-(i+1+ai)))

  a_list = b_list

print(*a_list)

Submission status: Time Limit Exceeded

Solution code:
NK = input().split()
N = int(NK[0])
K = int(NK[1])
 
A_ = list(map(int, input().split()))
 
for i in range(K):
  ltd = [1 for i in range(N)]
  for j in range(N):
    rng = A_[j]
    for d in range(1, rng+1):
      if j - d >= 0:
        ltd[j - d] += 1
      if j + d < N:
        ltd[j + d] += 1
  A_ = ltd
 
ans = ' '.join(map(str, A_))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
B = np.array([0]*len(A))

for i in range(K):
  B *=0
  for j in range(len(A)):
    llim = max([0, j-A[j]])
    ulim = min([len(A), j+A[j]+1])
    B[llim:ulim] = B[llim:ulim] + 1
  A=B+0

print(*A)

Submission status: Time Limit Exceeded

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):
        for j in range(max(0,i-A[i]),min(N,i+A[i]+1)):
            B[j] += 1

    # print(B)
    A = B

print(*B)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))  # 整数のリスト

    next_A = [0 for _ in range(N)]

    for _ in range(K):
        if sum(A) == N**2: break
        for i in range(N):
            if A[i] > N: continue
            for j in range(i-A[i], i+A[i]+1):
                if j >= 0 and j < N:
                    next_A[j] += 1
        A = next_A
        next_A = [0 for _ in range(N)]

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
  B = [1 for l in range(N)]
  for i in range(N):
    n = A[i]
    for j in range(1,n+1):
      if i-j>=0:
        B[i-j] += 1
        
      if i+j<=N-1:
        B[i+j] += 1
        
  A = B
A = [str(a) for a in A]
A = ' '.join(A)
print(A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
mask = [np.array(list(range(i))[::-1] + list(range(N+1-i))[1:]) for i in range(1,N+1)]
for k in range(K):
  nextA = [np.count_nonzero(np.array(A)-i >=0) for i in mask]
  A = nextA
  #print(A)
  if min(A)==N:
    break
print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

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

for k in range(K):
    left={}
    right={}
    for i in range(N):
        l=max(0,i-A[i])
        r=min(N-1,i+A[i])
        if l in left:
            left[l]+=1
        else:
            left[l]=1
        if r in right:
            right[r]+=1
        else:
            right[r]=1

    br=[]
    b=0
    m=N
    for i in range(N):
        if i in left:
            b+=left[i]
        br.append(b)
        m=min(m,b)
        if i in right:
            b-=right[i]
    if m==N:
        break
    A=copy(br)
print(*br)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy
n, K = map(int, input().split())
A = list(map(int, input().split()))

bef = copy.copy(A)
aft = [0 for _ in range(n)]
aft_array = np.array(aft)

for k in range(K):
    for i in range(n):
        a = bef[i]
        aft_array[max(0, i-a):min(n-1, i+a)+1]+=1
    if bef ==  aft_array.tolist():
        break
    bef = aft_array.tolist()
#     aft = [0 for _ in range(n)]
    aft_array = np.array(aft)
#     print(bef)
print(*bef)

Submission status: Time Limit Exceeded

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)

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:end] += 1

    A = B

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K, *A = map(int, read().split())
B = [0]*N
for _ in range(K):
  for i in range(N):
    a = max(0,i-A[i])
    b = min(N-1,i+A[i])
    for j in range(a,b+1):
      B[j] += 1
  if A == B:
    break
  A=B
  B = [0]*N
print(*A)

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
if K >= N:
    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)