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:
n,k = map(int, input().split())
a = list(map(int, input().split()))

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

    a = [b[i] for i in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
for count in range(K):
    area = []
    area = [[i2 + 1 for i2 in range(int(i + 1 - v - 0.5),int(i + 1 + v + 0.5))] for i,v in enumerate(A)]
    area = sum(area,[])
    newA = []
    for i,v in enumerate(A):
        newA.append(area.count(i + 1))
    A = newA
print(*A)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n, k = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters = [0]
dd = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters.extend(dd)


for times in range(k):
    lighted_positions = []
    for i, intense in enumerate(intense_counters):
        if i == 0:
            continue

        min = i - intense
        max = i + intense

        for lighted_position in range(min, max+1):
            if 0 < lighted_position and lighted_position <= n:
                lighted_positions.append(lighted_position)

    intense_counters = [0] * (n+1)
    for lp in lighted_positions:
        intense_counters[lp] += 1

print(" ".join(list(map(str, intense_counters[1:]))))

Submission status: Time Limit Exceeded

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

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

    A = Next.copy()
print(*Next)

# for i in range(K):
#     Next = A.copy()
#     for i in range(len(A)):
#         cnt = 0
#         for j in range(len(A)):
#             if abs(i-j) <= A[j]:
#                 cnt+=1
#         Next[i] = cnt
#     A = Next.copy()
# print(Next)

Submission status: Time Limit Exceeded

Solution code:
import math

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

a.insert(0, 0)

for i in range(k):
    ans = [1] * (n + 1)
    for j in range(1, n + 1):
        if a[j] > 0:
            x = math.ceil(j - a[j] - 0.5)
            y = math.floor(j + a[j] + 0.5)
            for t in range(max(x, 1), min(y + 1, n + 1)):
                if t != j:
                    ans[t] += 1
    a = ans

a = [str(s) for s in a]
a = ' '.join(a)
print(a[2:])

Submission status: Time Limit Exceeded

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

for i in range(k):
    new_list = [0 for _ in range(n)]
    start_list = [0 for num in range(n)]
    end_list = [0 for num in range(n)]
    for j, a in enumerate(a_list):
        if j-a > 0:
            start_list[j-a] += 1
        else:
            start_list[0] += 1
        if a+j < n:
            end_list[a+j] += 1
        else:
            end_list[n-1] += 1
    now_sum = 0
    # print(start_list)
    # print(end_list)
    for j in range(n):
        now_sum += start_list[j]
        new_list[j] = now_sum
        now_sum -= end_list[j]
    # print(new_list)
    a_list = new_list.copy()

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

Submission status: Time Limit Exceeded

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

for _ in range(K):
    b=[]
    for j in range(1,N+1):
        count=0
        for i in range(N):
            if i-a[i]+0.5<=j and j<=i+a[i]+1.5:
                count+=1
        b.append(count)
    a=b
print(" ".join(map(str,a)))

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict

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


def left_right(x, d):
    left = x - d - 0.5
    right = x + d + 0.5
    return left, right

for _ in range(K):
    dic = defaultdict(int)
    for i in range(N):
        l, r = left_right(i + 1, al[i])
        left = math.ceil(l)
        if left == 0:
            left += 1
        right = math.floor(r)
        for n in range(left, right + 1):
            dic[n] += 1
    al = list(dic.values())[:N]
print(*al)

Submission status: Time Limit Exceeded

Solution code:
#imos法で更新を繰り返す
#log回で終わる
from itertools import accumulate
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k):
    b=[0]*n
    for i in range(n):
        b[max(0,i-a[i])]+=1
        if i+a[i]+1<n:
            b[i+a[i]+1]-=1
    #print(b)
    a=list(accumulate(b))
    if a==[n]*n:
        break
print(" ".join(map(str,a)))

Submission status: Time Limit Exceeded

Solution code:
def solve(A,N,K):
    for k in range(K):
        C = [0 for _ in range(N+1)]
        #C[i]:i番目の電球を照らす電球の数
        for i in range(N):
            C[max(i-A[i],0)] += 1
            C[min(i+A[i]+1,N)] -= 1
        for i in range(1,N):
            C[i] += C[i-1]

        if C[0] == N or C[N-1] == N:
            for i in range(N):
                A[i] = N
            break
        else:
            for i in range(N):
                A[i] = C[i]
    return A

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

    ans = solve(A,N,K)

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    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

        A = [i for i in illumi]

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
import sys

def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    for m in range(k):
        B = [1] * n
        for i in range(n):
            for j in range(A[i]):
                if (i+1)+(j+1) < n+1:
                    B[(i+1)+(j+1)-1] += 1
                if (i+1)-(j+1) > 0:
                    B[(i+1)-(j+1)-1] += 1

        A = copy.deepcopy(B)

    print(*A)

if __name__ == '__main__':
    main()

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):
    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, = map(int, input().split())
for _ in range(K):
    counter = [0] * (N+2)
    for i, a in enumerate(A, 1):
        counter[max(0, i - a)] += 1
        counter[min(N+1, i + a + 1)] += -1
    for i in range(1, len(counter)): counter[i] += counter[i-1]
    A = counter[1:N+1]
    if sum(A) == N * N: break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
from numba import njit

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

@njit
def main(N, K, A):
    for i in range(K):
        B = np.zeros(N, dtype=np.int64)
        for j in range(N):
            st = max(0, j - A[j])
            ed = j + A[j] + 1
            B[st:ed] += 1
        #print(B)
        if np.all(B == N):
            A = B
            break
        A = B
    return A

if __name__ == "__main__":
    N, K = map(int, readline().split())
    A = np.array(readline().split(), dtype=np.int64)
    ans = main(N, K, A)
    print(*ans)

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
#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
        #print(str(x)+"が照らしている範囲")
        #print(left, right)
        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:
n,k = map(int,input().split())
ls = list(map(int,input().split()))
for _ in range(k):
    new = [0]*n
    for i in range(n):
        p = 0
        for l in range(1,n-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:
[n,k]=list(map(int,input().split()))
akarusa=list(map(int,input().split()))

for i in range(k):
    akarusanext=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        for k in range(kagen,jogen+1):
            akarusanext[k]+=1
    akarusa=akarusanext
    if akarusa==[n]*n:
        break

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, K: int, A: "List[int]"):
    for n in range(K):
        L = [0] * N
        for i in range(N):
            for j in range(A[i]+1):
                if j!=0:
                    if i-j>=0:
                        L[i-j] += 1
                    if i+j<N:
                        L[i+j] += 1
                else:
                    L[i+j] += 1
        A = L

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


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

for _ in range(k):
    b = [1] * n

    h = defaultdict(int)
    num = 0
    for i in range(n):
        if h[i] > 0:
            num -= h[i]
        b[i] += num
        num += 1
        h[i + 1 + a[i]] += 1
    
    h = defaultdict(int)
    num = 0
    for i in range(n - 1, -1, -1):
        if h[i] > 0:
            num -= h[i]
        b[i] += num
        num += 1
        h[i - 1 - a[i]] += 1

    a = b

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

Submission status: Time Limit Exceeded

Solution code:
N, K=(int(x) for x in input().split())
A=list(map(int, input().split()))
#print(N)
#print(K)
#print(A)
for i in range(0,K):
	A_partial = []
	for j in range(0, N):
		sum = 0
		for k in range(0, N):
			if j==k:
				sum = sum + 1
			else:
				if k-A[k]-0.5<j and k+A[k]+0.5>j:
					sum = sum + 1
					#print(i,",",j,",",k,",",sum)
		#print(sum)
		A_partial.append(sum)
	A = A_partial
print(*A)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from heapq import heappush,heappop

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

for k in range(K):
    tmp1=[0 for i in range(N)]
    tmp2=[0 for i in range(N)]
    
    h1=[]
    h2=[]
    num1=0
    num2=0
    for i in range(N):
        heappush(h1,A[i]+i)
        num1+=1
        tmp1[i]+=num1
        # print("h1",h1[0],i,)
        while h1[0]==i:
            # print("!")
            heappop(h1)
            num1-=1
            if len(h1)==0:
                break
        
        heappush(h2,Ar[i]+i)
        tmp2[i]=num2
        num2+=1
        # print("h2",h2[0],i)
        while h2[0]==i:
            # print("?")
            l=heappop(h2)
            num2-=1
            if len(h2)==0:
                break
    
    for i in range(N):
        A[i]=tmp1[i]+tmp2[-(1+i)]
    Ar=list(reversed(A))
    
    if set(A)==set([N]):
        break
# print(tmp1,tmp2)
# print(h1,h2)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import copy

def blight(dist,_i):

	l=_i-dist
	r=_i+dist+1
	if l<0:l=0
	if r>n:r=n
	for _ in range(l,r):
		ans[_]+=1



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

cnt=0
while cnt<k:
	ans=[0]*n
	for i in range(n):
		#print("old:",a)
		blight(a[i],i)
		#print(ans)
		#print("new:",a)
	cnt+=1
	a=copy.deepcopy(ans)
print(" ".join(map(str,ans)))

Submission status: Time Limit Exceeded

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


for k in range(K):
    D=[0]*(N+1)
    for i,d in enumerate(A):
        left=max(0,i-d)
        right= min(N-1,i+d)
        D[left]+=1
        D[right+1]-=1
    for i in range(N):
        D[i+1]+=D[i]
    A= D[:-1]

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for i in range(K):
    B = [0] * N
    for index, a in enumerate(A):
        for j in range(index-a,index+a+1, 1):
            if j < 0:
                continue
            if j >= N:
                break
            B[j] += 1
    A = copy.copy(B)
    
print(*B)

Submission status: Time Limit Exceeded

Solution code:

import copy
n, K = map(int, input().split())
A = list(map(int, input().split()))

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

for k in range(K):
    for i in range(n):
        a = bef[i]
        aft[max(0, i-a):min(n-1, i+a)+1] = map(lambda x: x+1, aft[max(0, i-a):min(n-1, i+a)+1])
    #     aft[max(0, i-a):min(n-1, i+a)] +=1
#         print(aft[max(0, i-a):min(n-1, i+a)+1])
    if bef == aft:
        break
    bef = copy.copy(aft)
    aft = [0 for _ in range(n)]
print(*bef)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import math
from decimal import Decimal, ROUND_DOWN


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, k) = [int(e) for e in lines[0].split(' ')]
    a = [int(e) for e in lines[1].split(' ')]

    return (n, k, a)


def solve(n, k, a):

    current = a.copy()
    next = [0 for i in range(n)]
    for _ in range(k):
        for i in range(n):
            strength = current[i]
            for j in range(max(i - strength, 0), min(i + strength + 1, n)):
                next[j] = next[j] + 1
        
        current = next.copy()
        next = [0 for i in range(n)]

    return ' '.join([str(e) for e in current])
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

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

def light_distance(x,power):
  return [x-power-0.5,x+power+0.5]

def light_power_position(power_range):
  start = power_range[0]
  end = power_range[1]
  return [1 if i>=start and end>=i else 0 for i in range(1,n+1)]

for i in range(k):
  number_light = [0 for i in range(n)]
  for j in range(1,n+1):
    number_light = list(map(sum, zip(number_light, light_power_position(light_distance(j,light_power[j-1])))))
  light_power = number_light
print(' '.join(map(str, light_power)))

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

for _ in B:
    print(_, end=' ')

Submission status: Time Limit Exceeded

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

def main():
    for k in range(K):
        li = [0 for i in range(N+1)]
        rsl = [0 for i in range(N+1)]


        for i in range(N):
            if A[i] != 0:
                li[max(0,i-A[i])]+= 1
                li[min(N,i+A[i]+1)]-= 1
        
        mm = 0
        for i in range(N):
            mm += li[i]
            if A[i]>0:
                A[i] = mm
            else:
                A[i] = mm +1
        # print(A)

        if min(A)>=N:
            break
    print(*A)



main()

Submission status: Time Limit Exceeded

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


def change(arr):
  newAs = [0] * n
  for i, a in enumerate(arr):
    for t in range(max(i - a, 0), min(i + a + 1, n)):
      newAs[t] += 1
  return newAs


for temp in range(min(k, 10**3)):
  As = change(As)
print(' '.join(map(str, As)))

Submission status: Time Limit Exceeded

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

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


for _ in range(K):
    counterlist = [0 for _ in range(N)]
    for i in range(N):
        d = A[i]
        u = max(0,i-d)
        v = min(N-1,i+d)
        for pl in range(u,v+1):
            counterlist[pl]+=1
    A = counterlist

print(*A)

Submission status: Time Limit Exceeded

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

a = [0] * N
flg = 0

for k in range(K):
    if a[0] == N:
        break
    a = [0] * N
    for i in range(N):
        a[max(0, i - A[i])] += 1
        if N - 1 >= (A[i] + i + 1):
            a[A[i] + i + 1] -= 1
    for j in range(N):
        A[j] = A[j - 1] if j > 0 else 0
        A[j] += a[j]
    # print("k=", k, A)


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(K):
    new_l = np.array([0]*N)
    for j in range(N):
        new_l = new_l + np.array([0]*max(0,j-l[j]) + [1]*(min(j,l[j])+1+min(l[j],N-1-j)) + [0]*max(0,N-1-(j+l[j])))
    l = new_l
    
print(*new_l)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, k = map(int, input().split())
a = np.array(input().split(), dtype=np.int64)

for j in range(k):
    b = np.zeros(n+1, dtype=np.int64)
    for i in range(n):
        b[max(i-a[i], 0)] += 1
        b[min(i+a[i]+1, n)] -= 1
    a = np.cumsum(b)[:-1]
    if np.all(a==n):
        print(*a)
        break
else:
    print(*a)

Submission status: Time Limit Exceeded

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

maxcnt = 0
for cnt in range(K):
    X = [maxcnt] * N
    for i in range(N):
        d = A[i]
        if d != N:
            for x in range(-1 * d, d + 1):
                if i + x >= 0 and i + x < N:
                    X[i + x] += 1
    for i in range(N):
        maxcnt = 0
        if X[i] == N:
            maxcnt += 1
        A[i] = X[i]
#    print(' '.join(map(str, A)))

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
nums=np.array(range(n))
leftdis=nums-a-0.5
rightdis=nums+a+0.5
for j in range(k):
  for i in range(n):
    a_i=np.count_nonzero(np.logical_and(leftdis<i,rightdis>i))
    a[i]=a_i
    #leftdis[i]=a_i-i-0.5
    #rightdis[i]=a_i+i+0.5
  leftdis=nums-a-0.5
  rightdis=nums+a+0.5
print(" ".join((str(x) for x in a)))

Submission status: Time Limit Exceeded

Solution code:
import math


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

    for i in range(k):
        a = solve(a)
        # print(" ".join([str(i) for i in a]))
        for i in a:
            if i != n:
                break
        else:
            return a
    return a


def solve(a):
    b = [0 for i in range(len(a))]

    for i, a_i in enumerate(a):
        for j in range(max(0, math.ceil(i - a_i - 0.5)), min(len(b), int(i + a_i + 0.5) + 1)):
            b[j] += 1
    return b


if __name__ == '__main__':
    result = main()
    print(" ".join([str(i) for i in result]))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
from decimal import *
import numpy as np
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
input = sys.stdin.readline

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


lcount = np.zeros(N, dtype=int)
for k in range(K):
    for i in range(N):
        minind = i-A[i] if i-A[i] > 0 else 0
        lcount[minind:i+A[i]+1] += 1
    A = lcount
    lcount = np.zeros(N, dtype=int)


print(" ".join(list(A.astype("unicode"))))

Submission status: Time Limit Exceeded

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


def change(arr):
  newAs = [0] * n
  for i, a in enumerate(arr):
    for t in range(max(i - a, 0), min(i + a + 1, n)):
      newAs[t] += 1
  return newAs


for temp in range(min(k, 10**4)):
  As = change(As)
print(' '.join(map(str, As)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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



for j in range(K):
    Alight=np.array([0]*N)
    for i in range(N):
        fro=i-A[i]
        to=i+A[i]+1
        if fro < 0:
            fro=0
        #for k in range(fro,to):
        Alight[fro:to]+=1
        #print(fro)
        #print(to)
        #print(Alight)
    A=Alight[:]

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

Submission status: Time Limit Exceeded

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



for i in range(k):
    result = np.array([0]*n, dtype=object)
    for j in range(n):
        count = 0
        
        if a_n[j] == n:
            result[j] =n
            continue
        for l in range(n):
            if l > j:
                if l-a_n[l]-0.5<j:
                    count += 1
            elif l < j:
                if l+a_n[l]+0.5>j:
                    count += 1
            else:
                count += 1
        result[j] =count
    a_n = result
    if all(i == n for i in a_n):
        break
    
ans=[str(a) for a in a_n]
ans=" ".join(ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A_temp=[0]*N
    for k in range(K):
        for i in range(N):
            for j in range(max(0,i-A[i]),min(N,i+A[i]+1)):
                A_temp[j]+=1
        A=A_temp
        A_temp=[0]*N
    print(' '.join(map(str,A)))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
current = a[:]
for _ in range(k):
    next = [1]*n
    stack = 0
    for j, v in enumerate(current):
        next[j] += int(str(stack)[-1])
        stack = str(stack)
        stack = stack[:len(stack)-1]
        if len(stack):
            stack = int(stack)
        else:
            stack = 0
        if v > 0:
            stack += int('1'*v)
    stack = 0
    next = next[::-1]
    for j, v in enumerate(current[::-1]):
        next[j] += int(str(stack)[-1])
        stack = str(stack)
        stack = stack[:len(stack) - 1]
        if len(stack):
            stack = int(stack)
        else:
            stack = 0
        if v > 0:
            stack += int('1' * v)
    current = next[::-1]
print(*current)

Submission status: Time Limit Exceeded

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

for _ in range(K):
    B = [sum(abs(x -y) <= A[y] for y in range(N)) for x in range(N)]
    A = B

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


n, k = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype=np.int64)

loop_cnt = 0
while loop_cnt < k:
    if all(a >= n):
        a = np.array([n] * n)
        break

    new_a = np.zeros(n, dtype=np.int64)

    for j in range(n):
        new_a[max(0, j - a[j]): min(n, j + a[j] + 1)] += 1

    a = new_a
    loop_cnt += 1

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

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=A[:]
for _ in range(K):
    t=[0]*(N+1)
    for i in range(N):
        ti=a[i]
        t[max(0,i-ti)]+=1
        t[min(N,i+ti+1)]-=1
    a=[]
    for i in range(N):
        a.append(t[i])
        if i>0:
            a[i]+=a[i-1]
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):
    B = [0]*N
    for j in range(N):
        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
    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 i in range(K):
  new = [0] * (N+1)
  for j in range(N):
    new[max(0, j-A[j])] += 1
    if j+A[j]+1 <= N-1:
      new[j+A[j]+1] -= 1
  A[0] = new[0]
  for j in range(1, N):
    new[j] += new[j-1]
    A[j] = new[j] 
  for ai in A:
    if ai != N:
      break
  else:
    break
    
print(' '.join([str(ai) for ai in 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):
  ans=[0]*N
  for j in range(N):
    num=A[j]
    for k in range(max([j-num,0]),min([j+num+1,N])):
      ans[k]+=1
    #print(ans,max([j-num,0]),min([j+num,N-1]))
  A=ans
  
  if ans[0]==N:
    break
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

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

for i in range(k):
  for j in range(n):
    for r in range(max(j-lamps[j], 0), min(j+lamps[j]+1, n)):
      lights[r] += 1
  lamps = lights[:]
  lights = [0 for i in range(n)]

l = [str(a) for a in lamps]
l = " ".join(l)
print(l)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(K):
    zero = np.array([0]*N)
    for j in range(N):
        if j + A[j] + 1 >= len(A):
            zero[j:] += 1
        else:
            zero[j:A[j]+j+1] += 1
        if j - A[j] - 1 < 0:
            zero[:j] += 1
        else:
            zero[j-A[j]:j] += 1
    if list(A) == list(zero):
        break
    else:
        A = zero

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

Submission status: Time Limit Exceeded

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

 
for _ in range(K):
  brighted = {}

  for i in range(N):
    light_min = max(i + 1 - A[i] - 0.5,0.5)
    light_max = min(i + 1 + A[i] + 0.5,N + 0.5)
    while 1:
      light_min += 1
      ac = int(light_min)
      if light_max >= ac:
        if ac not in  brighted:
          brighted[ac] = 1
        else:
          brighted[ac] += 1
      else:
        break

  for key, value in brighted.items():
    A[key-1] = value
    
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 j in range(K):
  B = [0]*N
  for i in range(N):
    l = max([0 , i - A[i]])
    r = min([N-1 , i+A[i]]) + 1
    for k in range(l,r):
        B[k] += 1
  A = B

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
cnt = 0
while True:
    cnt += 1
    new = [0 for _ in range(n)]
    for i in range(n):
        # for j in range(n):
        #     if abs(i-j) < arr[j]:
        #         # print(arr[i], arr[j], i, j)
        #         new[i] += 1
        new[max(0, i-arr[i])] += 1

        tmp = i+arr[i]+1
        # print(max(0, i-arr[i]), tmp, i)
        if tmp < n:
            new[tmp] -= 1

    for i in range(1, n):
        new[i] += new[i-1]
    # print(new)
    arr = new
    # print(arr)
    if min(arr) >= n or cnt >= k:
        # print(min(arr), cnt)
        break

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