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 itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

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):
        for l in range(max(0,j - a[j]), min(n,j + a[j] + 1)):
            ans[l] += 1
    if ans.count(n) == n:
        break
    else:
        for g in range(n):
            a[g] = ans[g]

for i in range(n):
    print(ans[i],end=" ")

Submission status: Time Limit Exceeded

Solution code:
n,k = (int(num) for num in input().split())
a = [int(num) for num in input().split()]

while k > 0:
    if min(a) < n:
        b = [0] * (n+1)
        for i in range(n):
            b[max(0,i-a[i])] += 1
            b[min(n,i + a[i]+1)] -= 1
        for i in range(1,n):
            b[i] += b[i-1]
        a = b[:n].copy()
    k-=1
    
ans = ""
for num in a:
    ans += str(num) + " "
    
print(ans)

Submission status: Time Limit Exceeded

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

import sys
import math

if K > 4*math.log(N):
    A = [N]*N
    print(' '.join(map(str, A)))
    sys.exit()
    

lenA = len(A)
for i in range(K):
    B = [0 for _ in range(lenA)]
#    print(B)
    for j in range(lenA):
        num = A[j]
#        print(j, num)
        B[max(0, j - num): min(lenA, j + num + 1)] = [b + 1 for b in B[max(0, j - num): min(lenA, j + num + 1)]]
#        print(j, B)
    if all([a == b for a, b in zip(A,B)]):
#        print('same')
        break
    else:
        A = B
#print(i+1)
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
tmp = input().split(' ')
A = []
for i in range(N):
    A = A + [int(tmp[i])]

Z = np.array([[abs(j - i) for j in range(N)] for i in range(N)])

B = [0]*5
while K > 0:
    K = K - 1
    for i in range(N):
        B[i] = np.count_nonzero(A >= Z[i])

    A[:] = B[:]

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

Submission status: Time Limit Exceeded

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

for _ in range(K):
    answer = [0 for _ in range(N)]
    for i in range(N):
        minus_area = (i + 1) - A[i] - 0.5
        plus_area = (i + 1) + A[i] + 0.5
        if minus_area < 0.5:
            minus_area = 0.5
        if plus_area > N + 0.5:
            plus_area = N + 0.5
        minus_area += 0.5
        plus_area -= 0.5
        for index in range(int(minus_area) - 1, int(plus_area)):
            answer[index] += 1
    if A == answer:
        break
    A = answer

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

Submission status: Time Limit Exceeded

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

def calc_plus(n):
  return n + 1

if K > N-1:
  list1 = [N]*N
  A = list1

for k in range(K):
  list1 = [0]*N
  for i in range(N):
    num1 = max(0, i-A[i])
    num2 = min(i+A[i]+1, N)
    list1 = list1[0:num1] + list(map(calc_plus, list1[num1:i]))+list1[i:i+1] +list(map(calc_plus, list1[i+1:num2])) + list1[num2:N]
  list1 = list(map(calc_plus, list1))
  A = list1
  
for l in range(N):
  print(A[l], end=" ")

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
keys = [i for i in range(N)]
tmp = {key: 0 for key in keys}

for t in range(K):
    if min(A) == N:
        break
    for i in range(N):  # N番目の電球が照らしている座標に1足す
        start = max(0, i - A[i])
        end = min(N, i + A[i] + 1)
        for j in range(start, end):
            tmp[j] += 1
    for l in range(N):
        A[l] = tmp[l]
    tmp = {key: 0 for key in keys}

print(*A)

Submission status: Time Limit Exceeded

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

for k in range(K):
    copy_A = [0]*N
    for i in range(N):
        now = A[i]
        for j in range(max(0, i-now), min(N, i+now+1)):
            copy_A[j] += 1
    A = copy_A[0:N]
    if min(A) == N:
        break

print(*A)

Submission status: Time Limit Exceeded

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

    def light_range(A):
        lighted = np.zeros(N, dtype=np.int64)
        for i, a in enumerate(A):
            lighted[max(0, i-a): min(N, i+a+1)] += 1
        return lighted
    

    def handle():
        nonlocal A
        lighted = light_range(A)
        A = lighted
        #print(f"lighted={lighted}")

    for _ in range(K):
        handle()
    
    print(" ".join(map(str, A)))



if __name__ == '__main__':
    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 = np.array(xnxn(flag="l"))
for _ in range(k):
    add = np.zeros(n, dtype="int")
    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
        add[idx_min:idx_max+1] = add[idx_min:idx_max+1]+1
    a = add

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

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]*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:
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))

#照らせる範囲
def r(i,A):
    x1=math.ceil(i+1-A[i]-0.5)
    x2=i+1+A[i]+0.5
    X=[]
    for l in range(x1,int(x2)+1):
        if(l>0):
            X.append(l)
    return X


for k in range(K):
    B=[0]*N
    for i in range(N):
        for m in r(i,A):
            if(m-1<N):
                n=m-1
                B[n]+=1
    A=B
print(str(A).replace(',',' ').replace('[','').replace(']',''))

Submission status: Time Limit Exceeded

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

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    LampList = list(map(int, input().split()))
    
    if N <= K:
        LampList = [N for i in range(N)]
        for i in range(N):
            print(LampList[i], end=' ')
    else:
        for i in range(K):
            tmpList = [0 for i in range(N)]
            for p in range(N):
                Start = p - LampList[p]
                Stop = p + LampList[p] + 1
                if Start < 0:
                    Start = 0
                if Stop > N:
                    Stop = N
                for q in range(Start, Stop):
                    tmpList[q] += 1
            
            LampList = tmpList
            if all(elem == N for elem in LampList):
                break
        
        for i in range(N):
            print(LampList[i], end=' ')
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n,k = map(int, input().split())
d = np.array(list(map(int, input().split())))
l = np.arange(n)
ans = np.array([0]*n)
cnt = 0

def func(x_left, x_right):
  for x_l,x_r in zip(x_left,x_right):
      ans[x_l:x_r] += 1

while True:
  if np.all(d==n):
    ans = d
    break

  if cnt == k:
    break

  ans *= 0
  x_left = l-d
  x_left[x_left < 0] = 0
  x_right = l+d+1
  x_right[x_left > n] = n
  func(x_left, x_right)
  cnt += 1
  if np.all(d+n==ans):
    ans+=(k-cnt)*n
    break
  else:
    d = ans.copy()
    continue

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

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.zeros(N, dtype=np.int)
    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
        for j in range(lower, higher):
            light[j] += 1
    lamp_list = light

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

Submission status: Time Limit Exceeded

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

# 一度照らされると二度目以降は確実に照らされるはず。
for i in range(K):
    # j番目の電球を操作
    B = np.array([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 = B.copy()

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

Submission status: Time Limit Exceeded

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

    for i in range(K):
        next_A_list = [0 for i in range(len(A_list))]

        for denkyu_num in range(len(A_list)):
            for j in range(A_list[denkyu_num] + 1):
                if denkyu_num + j < len(A_list):
                    next_A_list[denkyu_num + j] += 1
                if denkyu_num - j >= 0 and j != 0:
                    next_A_list[denkyu_num - j] += 1
            #print(j, next_A_list)

        A_list = next_A_list
        #print()

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

Lamps()

Submission status: Time Limit Exceeded

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

for k in range(K):
    tmp = [0] * N
    for n in range(N):
        if A[n] > 0:
            if n - A[n] > 0 and n + A[n] < N:
                for i in range(n - A[n], n + A[n] + 1):
                    tmp[i] += 1
            elif n - A[n] > 0:
                for i in range(n - A[n], N):
                    tmp[i] += 1
            elif n + A[n] < N:
                for i in range(0,n + A[n] + 1):
                    tmp[i] += 1
            else:
                for i in range(N):
                    tmp[i] += 1

        else:
            tmp[n] += 1


    A = tmp

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline


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

    for _ in range(K):
        B = np.zeros(N)
        for i, a in enumerate(A):
            bottom = i - a
            top = i + a + 1
            if bottom < 0:
                bottom = 0
            if top > N:
                top = N
            B[bottom:top] += np.ones(top-bottom)
        A = list(map(int, list(B)))

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,k = (int(num) for num in input().split())
a = [int(num) for num in input().split()]

while k > 0:
    if min(a) < n:
        b = [0] * (n+1)
        for i in range(n):
            b[max(0,i-a[i])] += 1
            b[min(n,i + a[i]+1)] -= 1
        for i in range(1,n):
            b[i] += b[i-1]
        a = b[:n].copy()
        k-=1
    
ans = ""
for num in a:
    ans += str(num) + " "
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:

import numpy as np

def main():
    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(min(K,40)):
        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)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import jit

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

@jit
def sousa(A, N, K):
    for k in range(K):
        wa = np.zeros(N)
        for i in range(N):
            lights = np.zeros(N)
            lights[np.max([0, i-A[i]]):np.min([N, i+1+A[i]])] = 1
            wa = wa + lights
        A = list(map(int, wa))
    return A

A = sousa(A, N, K)
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
#from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353
#from decimal import Decimal

n,k=mdata()
A=mdata()
for i in range(k):
    A1=[0]*(n+1)
    for j in range(n):
        A1[max(0,j-A[j])]+=1
        A1[min(n,j+A[j]+1)]-=1
    flag=True
    A[0]=A1[0]
    for j in range(1,n):
        A1[j]+=A1[j-1]
        A[j]=A1[j]
        if A1[j]!=n:
            flag=False
    if flag==True:
        break
print(*A)

Submission status: Time Limit Exceeded

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

for i in range(K):
    cnt=[0]*N
    if min(A)>N:
        A=[N]*N
        continue
    for j in range(N):
        p=A[j]
        for k in range(max(0,j-p),min(j+p+1,N)):
                cnt[k]+=1
    A=cnt

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

Submission status: Time Limit Exceeded

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

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

for ii in range(k):
	if ii == 0:
		ans = [0]*n
		for i in range(n):
			if arr[i] == 0:
				ans[i] = 1
			else:
				ans[i] = arr[i]
	else:
		ans = [0]*n
	for x in range(n):
		for ll in range(x-arr[x],x+arr[x]+1):
			if 0<=ll<=n-1:
				if x==ll:continue
				ans[ll] += 1
	if ii!=0 :ans = [i+1 for i in ans]
	#print("ans : ",ans)
	arr = ans[:]
	if ii > n//2:
		break
print(*arr)

Submission status: Time Limit Exceeded

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

def one(x):
    return x+1

for k in range(K):
    B=[0]*N
    for i in range(N):
        p=i-A[i]
        q=i+A[i]
        if i-A[i]<=0:
            p=0
        elif i+A[i]>=N:
            q=N-1
        B[p:q+1]=map(one,B[p:q+1])
        #print(p,q,A[i],i-A[i],i+A[i],A,B)
    A=copy.copy(B)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import copy
n,k = (int(x) for x in input().split())
la = list(map(int, input().split()))
if k >= n-1-min(la):
  ans = [n]*n
  print(' '.join(map(str, ans)))
else:
  for i in range(k):
    ans = [0]*n
    for j in range(n):
      s = max(0, j-la[j])
      e = min(n, j+la[j])
      ans[s:e+1] = [x+1 for x in ans[s:e+1]] 
    if min(ans)==n:
      break
    la = copy.copy(ans)
  print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

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 jit


@jit
def loop(N,K,A):
    for j in range(K):
        B = np.zeros_like(A)
        for i in range(N):
            temp = A[i]
            left = i - temp
            right = i + temp + 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)

    res = loop(N,K,A)

    print(*res)



main()

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A_list = [0] + [int(e) for e in input().split()]

steady_state_A_list = [N for _ in range(N+1)]

#そのままやると10**5 **2　でTLE
#自分の座標を通過するまでは、自分の明るさ＝照射範囲は変わらない

#is_lighted[i][j]…iの座標のランプがjを照らすなら1否なら0の行列
#これで照らされる個数をカウントしていけばOK

edge = [[0 for _ in range(N+2)]]
center = [[0] + [0 for _ in range(1,N+1)] + [0] for i in range(N)]
is_lighted = edge + center + edge

def calc_lighted_area():
    for i in range(1,N+1):
        d = A_list[i]
        
        #照射範囲を求める
        if i-d < 0:
            left_side = 0
        else:
            left_side = i-d

        if i+d > N:
            right_side = N+1
        else:
            if d != 0:
                right_side = i+d+1
            else:
                right_side = left_side + 1
        
        is_lighted[i][left_side:right_side] = [1 for i in range(right_side - left_side)]

#for i in range(1,N+1):
#    print(is_lighted[i][1:N+1])

calc_lighted_area()

for j in range(K):
    for i in range(1,N+1):
        Bi = sum([row[i] for row in is_lighted])        
        A_list[i] = Bi
    calc_lighted_area()

    if A_list == steady_state_A_list:
        break

print(' '.join(map(str, A_list[1:N+1])))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.insert(0,0)
X = {i:0 for i in range(-2*N,4*N+2)}
k = 0
while k<K:
    for i in range(1,N+1):
        d = A[i]
        X[2*i-2*d-1] += 1
        X[2*i+2*d+1] -= 1
    for i in range(-2*N+1,4*N+2):
        X[i] += X[i-1]
    for i in range(1,N+1):
        A[i] = X[2*i]
    X = {i:0 for i in range(-2*N,4*N+2)}
    cnt = 0
    for i in range(1,N):
        cnt += A[i]
    if cnt==N*N:
        break
    k += 1
print(*A[1:])

Submission status: Time Limit Exceeded

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

for i in range(k):
  b = [ 0 for bi in range(n) ]
  for j in range(n):
    b[j] += 1
    for bb in range(a[j]):
      if  j + bb + 1 < n :
        b[j + bb + 1] += 1
      if  j - bb - 1 >= 0 :
        b[j - bb - 1] += 1

  allflg = True
  for ii in range(len(b)):
    a[ii] = b[ii]
    if b[ii] != n:
      allflg = False
  if allflg == True:
    break
    
print(b[0],end="")
for i in b[1:]:
  print(" {}".format(i),end="")
print()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

N,K = map(int, input().split())
As = np.array(list(map(int, input().split())))

def light(As,N):
    A0 = np.array([0] * N)
    for i in range(N):
        lp = As[i]
        lmin = max(0, i - lp)
        lmax = min(N - 1, i + lp)
        A0[lmin:lmax + 1] += 1
    return A0

for i in range(K):
    As = light(As, N)

print(*As,sep=" ")

Submission status: Time Limit Exceeded

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

#print([0] *n)

for _ in range(k):
    bn = [0] *n
    for i in range(n):
        for j in range(max(i-an[i],0), min(n, i+an[i]+1)):
            bn[j] += 1
            #print(bn)
    an = bn

print(*an)

Submission status: Time Limit Exceeded

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

from itertools import accumulate

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

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    print(A_d[i], end=" ")

Submission status: Time Limit Exceeded

Solution code:
import copy as cp
import numpy as np

N, K =map(int, input().split())
A = [int(i) for i in input().split()]
A = np.array(A)

if K>N:
    A=[N]*N

else:
    for i in range(K):
        min_elem = N
        A_old = A.copy()
        A = np.zeros(N, dtype=int)
        starts = [0]*N
        ends = [0]*N
        for j in range(N):
            elem = A_old[j]
            starts[max(j-elem, 0)] += 1
            ends[min(j + elem, N-1)] += 1
            if elem < min_elem:
                min_elem = elem
        if min_elem==N:
            A = A_old.copy()
            break
        now = 0
        for j in range(N):
            now += starts[j]
            A[j] += now
            now -= ends[j]
        
print(*A)

Submission status: Time Limit Exceeded

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

for _ in range(K):
    count_list = []

    for x in range(len(given_list)):
        count = 0
        trg_place = x

        for l in range(len(given_list)):
            rela_place = l

            if abs(trg_place - rela_place) <= 0.5 + given_list[l]:
                count += 1
            else:
                count += 0
        count_list.append(count)
    
    given_list = count_list

L=[str(a) for a in given_list]
L=" ".join(L)
print(L)

Submission status: Time Limit Exceeded

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

def add(o):
    return o + k - i - 1

for i in range(k):
  a_c = [0 for y in range(n)]
  for j in range(n):
    ax = a[j]
    for m in range(-ax, ax+1):
      if j+m >= 0 and j+m < n:
        a_c[j+m] += 1
  a = a_c
  if min(a) >= n:
    a = list(map(add, a))
    break

print(*a)

Submission status: Time Limit Exceeded

Solution code:
class Range_BIT:
    def __init__(self, n):
        self.n = n
        self.bit0 = [0]*(n+1)
        self.bit1 = [0]*(n+1)
    
    def _Add(self, k, x, is_bit0=True):
        if is_bit0 == True:
            data = self.bit0
        else:
            data = self.bit1
        while k <= self.n:
            data[k] += x
            k += k & -k
    
    def _Get(self, data, k):
        s = 0
        while k:
            s += data[k]
            k -= k&-k
        return s
    
    """ 配列の獲得 """
    def Array(self):
        array = [0]*(n+1)
        for i in range(self.n):
            array[i] = self.Get(i+1,i+2)
        return array[:-1]
    
    """ 区間[l:r)に対してxを加算 """
    def Add(self, l, r, x):
        self._Add(l, -x*(l-1), is_bit0=True)
        self._Add(r, x*(r-1), is_bit0=True)
        self._Add(l, x, is_bit0=False)
        self._Add(r, -x, is_bit0=False)
    
    """ 区間[l:r)の総和 """
    def Get(self, l, r):
        Pi = self._Get(self.bit1, r-1)*(r-1) - self._Get(self.bit1, l-1)*(l-1)
        Qi = self._Get(self.bit0, r-1) - self._Get(self.bit0, l-1)
        return Pi+Qi


n,k = map(int,input().split())
A = list(map(int,input().split()))
for j in range(k):
    if j==0:
        rbit = Range_BIT(n)
        for i,a in enumerate(A):
            rbit.Add(max(1,i+1-a), min(i+2+a, n+1), 1)
    else:
        A_ = rbit.Array()
        rbit = Range_BIT(n)
        for i,a in enumerate(A_):
            rbit.Add(max(1,i+1-a), min(i+2+a, n+1), 1)
print(*rbit.Array())

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
cur=A
N2=N*N
for _ in range(K):
    nex=[0]*N
    for i in range(N):
        d=cur[i]
        for j in range(-d,d+1):
            if 0<=i+j<N:
                nex[i+j]+=1
    cur=nex
    if sum(cur)==N2:
        break
print("{}".format(cur[0]),end='')      
for i in range(1,N):       
    print(" {}".format(cur[i]),end='')
print()

Submission status: Time Limit Exceeded

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

if k > (n // 2):
    ion = 1;
        
else:
    for i in range(k):
        b = [0] * n;
    
        for p in range(n):
            for q in range(max(p-a[p],0),min(p+a[p]+1,n)):
                b[q] += 1;
                
        if b.count(n) == n:
            ion = 1;
            break;
                
        for v in range(n):
            a[v] = b[v];
        
if ion == 0:
    for j in range(n):
        print(a[j],end = " ");
else:
    for j in range(n):
        print(n,end = " ");

Submission status: Time Limit Exceeded

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

for turn in range(min(n, k)):
    status = [0] * n
    for x in range(n):
        for y in range(n): 
            if x + 1 - a[x] - 0.5 < y + 1 and y + 1 < x + 1 + a[x] + 0.5:
                status[y] += 1
    a = status
print(' '.join(str(n) for n in a))

Submission status: Time Limit Exceeded

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


for m in range(0,k):
    temp=[0]*n
    for i in range(0,n):
        d=a[i]
        if d !=0 :
            for x in range(i-d, i+d+1):
                if x >= 0 and x < n :
                    temp[x]+=1
        else:
            temp[i]+=1
    a=copy.copy(temp)

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

Submission status: Time Limit Exceeded

Solution code:
# C
import copy

n, k = map(int, input().split())
a_list = [int(x) for x in input().split()]
o_list = copy.deepcopy(a_list)

for i in range(k):
    _o_list = [0]*n
    for j in range(n):
        _t = o_list[j]
        _s, _e = j-_t, j+_t
        for x in range(max(_s, 0), min(_e+1, n)):
            _o_list[x] += 1
    o_list = copy.deepcopy(_o_list)
    if o_list == [n]*n:
        break
print(*o_list)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

n, k = [int(v) for v in input().split()]
init_lamps = [int(v) for v in input().split()]


def step(lamps):
    def count_max(lamps):
        return len([0 for v in lamps if v == n])

    if count_max(lamps) == n:
        return None
    new = [1 for _ in range(len(lamps))]
    heap = []
    for i, v in enumerate(lamps):
        while len(heap) > 0 and heap[0] < i:
            heappop(heap)
        new[i] += len(heap)
        if v > 0:
            heappush(heap, i + v)
    heap = []
    for i, v in enumerate(reversed(lamps)):
        while len(heap) > 0 and heap[0] < i:
            heappop(heap)
        new[n - i - 1] += len(heap)
        if v > 0:
            heappush(heap, i + v)
    return new


lamps = init_lamps
for _ in range(k):
    lamps = step(lamps)
    if lamps is None:
        lamps = [n for _ in range(n)]
        break

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_array = np.array(list(map(int, input().split())))

for k in range(K):

    B_list = list()
    R_list = list()

    inf_array = np.array(range(N)) + 1 - A_array - 0.5
    sup_array = np.array(range(N)) + 1 + A_array + 0.5
    
    inf_int_array = np.ceil(inf_array).astype(int)
    sup_int_array = np.floor(sup_array).astype(int)
    
    
    for m in range(N):
        R_list = R_list + list(range(inf_int_array[m], sup_int_array[m] + 1))
    
    
    for m_2 in range(N):    
        B_list.append(R_list.count(m_2 + 1))
    
        A_array = np.array(B_list).copy()
        
print(' '.join(map(str, A_array)))

Submission status: Time Limit Exceeded

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

def func(tuyosa):
  basho = []
  # 光が当たっている部分
  for i in range(n):
    min = i + 1 - tuyosa[i]
    max = i + 1 + tuyosa[i]
    add_list = []
    a = 0
    while a <= n:
      basho.append(min)
      min += 1
      if min > max:
        break
   # 次の強さ
  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:
def main():
    N, K = map(int,input().split())
    Light = list(map(int,input().split()))
 
    for i in range(K):
        Count = [0 for j in range(N)]
        for k in range(1,N+1):
            
            for l in range(max(1,k-Light[k-1]),min(N+1,k+Light[k-1]+1)):
            	Count[l-1] += 1
        Light = Count
 
    print(" ".join(map(str,Light)))
  
if __name__ == '__main__':
    main()