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()))

dic = {}
base_dic = {}

for i, j in enumerate(A, 1):
    dic[i] = j
    base_dic[i] = 0

for l in range(K):

    dic_copy = dic.copy()
    dic = base_dic.copy()

    for i, j in dic_copy.items():
        low = i - j
        high = i + j
        for k in range(low, high + 1):
            if 1 <= k <= N:
                dic[k] += 1

ans = []
for v in dic.values():
    ans.append(v)
ans = map(str, ans)
ans = " ".join(ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
num=0
ans=[0]*n
def abs_1(num1):
    return(abs(num1))
for i in range(k):
    ans=[0]*n
    for j in range(n):
        for l in range(n):
            if abs_1(j-l)<=a[l]:
                ans[j]+=1
    a=ans
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numba

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

@numba.jit
def answer(N,K,A):
    for count in range(K):
        A = [list(itertools.chain.from_iterable([[i2 + 1 for i2 in range(int(i + 1 - v - 0.5),int(i + 1 + v + 0.5))] for i,v in enumerate(A)])).count(i + 1) for i,v in enumerate(A)]
    return A

A = answer(N,K,A)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
if N / 2 + 1 < K:
    K = int(N / 2) + 1
A_list = list(map(int, input().split()))

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

Submission status: 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)

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:
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[max(0, i-A[i]):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
input=sys.stdin.readline
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:
#!/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):
#            print(L)
            for j in range(N):
#                print(i, A[j], abs(j-i))
                if A[j] >= abs(j-i):
                    L[i] += 1
#        print(L)
        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:
N,K = map(int,input().split())
A = list(map(int,input().split()))

for z in range(K):
  i_count = [0]*len(A) #座標iを照らすライトの数
  for i in range(1,len(A)+1):
    light = A[i-1]
    for x in range(i-light,i+light+1):
      if x >= 1 and x <= len(A):
        i_count[x-1] += 1
  A = i_count
print(*A, end=' ')

Submission status: Time Limit Exceeded

Solution code:
n, K = map(int, input().split())
a = list(map(int, input().split()))
nexta = [0] * len(a)
for i in range(K):
  for j in range(len(a)):
    range_min = min(len(a), max(1, (j+1)-a[j]))
    range_max = max(1, min(len(a), (j+1)+a[j]))

    for k in range(range_min-1, range_max):
      nexta[k] += 1

  for l in range(len(a)):
    a[l] = nexta[l]

  if i != (K-1):
    nexta = [0] * len(a)

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    if K >= N:
        print(' '.join([str(N) for _ in range(N)]))
        return
    for _ in range(K):
        imos = [0 for _ in range(N)]
        for i, a in enumerate(A):
            left = max(0, i - a)
            imos[left] += 1
            right = i + 1 + a
            if right <= N - 1:
                imos[right] -= 1
        for i in range(1, N):
            imos[i] += imos[i - 1]
        A = imos
    print(' '.join(map(str, A)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
A = input().split()
AK = [[0 for j in range(N)] for i in range(K+1)]
for l in range(N):
  AK[0][l] = int(AK[0][l]) + int(A[l])

for m in range(1,K+1,1):
  for o in range(N):
    d = AK[m-1][o]
    for x in range(N):
      if((o+1-d-0.5) < (x+1)) and ((x+1) < (o+1+d+0.5)):
        AK[m][x] = AK[m][x] +1
print(*AK[m])

Submission status: Time Limit Exceeded

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

def f(x):
    if x == 0:
        return ls
    else:
        lsa = [0 for i in range(n)]
        lsb = f(x-1)
        for j in range(n):
            if lsb[j] == 0:
                lsa[j] += 1
            else:
                if lsb[j] - j - 1 < 0:
                    if j + lsb[j] - n < 0:
                        for l in range(j -lsb[j], j + lsb[j] + 1):
                            lsa[l] += 1
                    else:
                        for l in range(j - lsb[j], n ):
                            lsa[l] += 1
                else:
                    if j + lsb[j] - n < 0:
                        for l in range(j + lsb[j] + 1):
                            lsa[l] += 1
                    else:
                        for l in range(n):
                            lsa[l] += 1
        return lsa

for m in range(n):
    print(f(k)[m], end = " ")

Submission status: Time Limit Exceeded

Solution code:
import copy
import math


N, K = map(int, input().split())
a = [0] + list(map(int, input().split()))

for k in range(K):
    b = [0] * (N + 1)
    for i in range(1, N+1):
        d_1 = max(1, math.ceil(i - a[i] - 0.5))
        d_2 = min(N, math.floor(i + a[i] + 0.5))
        for j in range(d_1, d_2+1):
            b[j] += 1
    a = copy.deepcopy(b)
    if a.count(N) == N:
        break

print(' '.join(map(str, a[1:])))

Submission status: Time Limit Exceeded

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

# 計算はimos法でできそう
# O(N*K)になってしまう
for _ in range(K):
    tmp = [0] * (N+1)
    for i in range(N):
        tmp[max(0, i-A[i])] += 1
        tmp[min(N-1, i+A[i]) + 1] -= 1

    ans = [0]*N
    A[0] = tmp[0]
    for i in range(1, N):
        A[i] = A[i-1] + tmp[i]

    # print(*A)
    if sum(A) == N*N:
        break
print(*A)

Submission status: Time Limit Exceeded

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

for x in range(k):
    new_a = [0]*n
    for j,l in enumerate(a):
        for i in range(-l,l+1):
            if j+i >= 0 and j+i<n:
                new_a[j+i]+=1
    a = new_a

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

for k in range(K):
    B = [0]*N
    for i in range(N):
        for a in range(A[i] + 1):
            if a == 0:
                B[i] += 1
            else:
                if i + a <= N-1:
                    B[i + a]+= 1
                if i-a >= 0:
                    B[i - a] += 1
    if k != K-1:
        A = B
    else:
        for i in range(N):
            print(B[i], "", end = '')

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    dict = {}
    temp = {}
    for i in range(N):
        dict[i+1] = A[i]
        temp[i+1] = 0

    for j in range(K):
        for m in range(1,N+1):
            if dict[m] < N:
                break
            else:
                if m == N:
                    ans = list(dict.values())
                    ans2 = str(ans[0])
                    for i in range(1,N):
                        ans2 += (' ' + str(ans[i]))
                    return(ans2)
                continue

        for h in range(1,N+1):
            temp2 = dict[h]
            for n in range(h-temp2,h+temp2+1):
                if n <= 0:
                    continue
                elif n > N:
                    break
                else:
                    temp[n] += 1

        for i in range(1,N+1):
            dict[i] = temp[i]
            temp[i] = 0

    ans = list(dict.values())
    ans2 = str(ans[0])
    for i in range(1,N):
        ans2 += (' ' + str(ans[i]))
    return(ans2)

print(main())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
bb = np.array(a, dtype=np.int64)
# print(bb)
check = np.full(n, n, dtype=np.int64)

for i in range(k):
    #d = [0] * n
    d = np.zeros(n, dtype=np.int64)
    #temp = bb
    for j in range(1, n + 1):
        pp = bb[j - 1]

        if (pp == 0):
            d[int(j - 1)] += 1
            # print(d)
            continue
        if (pp == n):
            d += 1
            # print(d)
            continue

        left = j - bb[j - 1] - 1
        # print(left)
        if (left < 0):
            left = 0
        right = j + bb[j - 1]
        #print('R: ',right)
        if (right > n - 1):
            right = n
        #print('L&R: ', left, right)

        d[int(left): int(right)] += 1
        #print(j, d)

    bb = d

    if (all(bb == check)):
        break


ans = [str(i) for i in bb]
# print(ans)
print(' '.join(ans))

#s = ','.join(l)

Submission status: Time Limit Exceeded

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

for i in range(k):
    r = [0] * n
    for j in range(n):
        for d in range(a[j] * 2 + 1):
            p = j - a[j] + d
            if p >= 0 and p < n:
                r[p] += 1    
    a = r
    
print(' '.join(map(str, a)))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math
    
N, K = mi()
A = li()

#light = [0] * (N+2)
#A = [0] + A + [0]
#print(math.log(N, 2))
'''
thre = 0
for i in range(N):
    if A[i] < i:
        thre = max(thre, i-A[i])
'''
if K > pow(N, 0.5) + 1:
        for i in range(N):
            print(N, '', end='')
        print()
        exit()


for i in range(K):
    new = [0] * (N+1)
    for j in range(N):
        new[max(j-A[j], 0)] += 1
        new[min(j+A[j]+1, N)] += -1
        #print(new)
    new = list(accumulate(new))
    A = new[:N]

for i in range(N):
    print(A[i], '', end='')
print()

Submission status: Time Limit Exceeded

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

for mou in range(K):
    newA = [0]*N
    count = 0
    for i in A:
        for j in range(-i,i+1):
            if count+j >= 0 and count + j < N:
                newA[count+j] += 1
        count +=1
    A = newA
print(' '.join(map(str,A)))

Submission status: Time Limit Exceeded

Solution code:
N,K,*A = map(int,open(0).read().split())

for i in range(K):
    after = [0] * N 
    for a in range(N):
        if A[a] == 0:
            after[a] += 1
        else:
            left = max(0,a-A[a])
            right = min(a+A[a],N-1)
            for aa in range(left, right+1):
                after[aa] += 1
    A = after[:]                
print(*after,sep=" ")

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 njit


@njit
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:
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A_num = [1 for n in range(N)]
for k in range(K):
    for n in range(N):
        if A[n] != 0:
            # 照らしている箇所
            add_area_min = math.ceil(max(n - A[n] - 0.5, 0))
            add_area_max = int(min(n + A[n] + 0.5, N-1))
            for i in range(add_area_min, add_area_max+1):
                if i != n:
                    A_num[i] += 1
    # 強さを更新
    for i in range(N):
        if A_num[i] != 1:
            A[i] = A_num[i]
    A_num = [1 for n in range(N)]  # 初期化
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

num_of_lamps, num_of_operation = map(int, input().split())
intensitys = np.array(list(map(int, input().split())))

coordinates = np.arange(1, len(intensitys) + 1)

intensity_area_min = []
intensity_area_max = []

for o in range(num_of_operation):
    intensity_area_min = coordinates - intensitys - 0.5
    intensity_area_max = coordinates + intensitys + 0.5

    # i + 1が自分の座標
    for i in range(num_of_lamps):
        # 自分より大きい（自分除く）の座標indexのminリストの中から自分の座標より小さいものを探してカウント
        min_count = np.count_nonzero(intensity_area_min[i+1:] <= i + 1)
        # 自分より小さい（自分除く）の座標indexのmaxリストの中から自分の座標より大きいものを探してカウント
        max_count = np.count_nonzero(intensity_area_max[:i] >= i + 1)

        # + 1は自分
        intensitys[i] = min_count + max_count + 1

    if np.all(intensitys >= num_of_lamps):
        break

out = ",".join(map(str, intensitys))
print(out.replace(',', ' '))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(0,k):
  npb=np.zeros(n, dtype=int)
  for j in range(0,n):
    js=j-npa[j]
    je=j+npa[j]
    if (js <=0): js=0
    if (je >=n-1): je=n-1
    npb[js:je+1]+=1

  npa=npb

print (*npa)

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

printed = set()
printed_lst = []
bl = []
for x 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]
    bl = [str(i) for i in al]
    bls = ''.join(bl)
    printed.add(bls)
    printed_lst.append(bls)
    if len(printed) != len(printed_lst):
        s = printed_lst.index(bls)
        s2 = x
        amari = (K-s)%(s2-s)
        ans = printed_lst[s+amari]
        print(ans)
        exit()

print(' '.join(bl))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A = list(map(int, input().split()))
def light(A,K):
    ans=[0]*N
    if K==0:
        A=[str(a) for a in A]
        p=" ".join(A)
        return print(p)
    else:
        for x in range(N):
            ans[x]+=1
            if A[x]==0:
                continue
            else:
                for p in range(1,A[x]+1):
                    if x-p>=0:
                        ans[x-p]+=1
                    if x+p<=N-1:
                        ans[x+p]+=1
        return light(ans,K-1)
light(A,K)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit


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

@njit
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())
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 mina >= 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:
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)

for i in range(K):
    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
    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:
import sys
input = sys.stdin.readline

def main():
    n,k = map(int,input().split())
    a = list(map(int, input().split()))
    ans = [0 for _ in range(n+1)]
    for _ in range(k):
        ans = [0 for _ in range(n+1)]
        for i in range(n):
            [l,r] = [max(0,i-a[i]),min(n-1,i+a[i])]
            ans[l] += 1
            ans[r+1] -= 1
        for i in range(n):
            ans[i+1] += ans[i]
        a = ans
        if min(ans) >= n:
            print(*[n for _ in range(n)])
            return
    x = []
    for i in range(n):
        x.append(ans[i])
    print(*x)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#C 
n,k = map(int,input().split())
a = list(map(int,input().split()))
import numpy as np
def sim(a):
    a = np.array(a)
    new = np.array([1 for _ in range(len(a))])
    for i in range(len(a)):
        if a[i] != 0:
            if i-a[i] < 0:
                mi = 0
            else:
                mi = i-a[i]
            if i+a[i] > len(a):
                ma = len(a)-1

            else:
                ma = i+a[i]

            new[mi:ma+1] += 1
            new[i] -= 1
        
    return new

flg = True
for i in range(k):
    a = sim(a)
    if set(a) == n:
        a = a.tolist()
        print(*a)
        flg = False
        break
if flg:
    a = a.tolist()
    print(*a)

Submission status: Time Limit Exceeded

Solution code:
from copy import copy
from collections import deque
import bisect
from bisect import bisect_left, bisect_right
from itertools import accumulate

n, k = map(int, input().split())
l = deque()
for i in input().split():
    l.append(int(i))
for i in range(k):
    r = deque(0 for i in range(n))
    for j in range(n):
        if l[j] == 0:
            r[j] += 1
        else:
            for m in range(l[j], -1*l[j]-1, -1):
                if m == 0:
                    r[j+m] += 1
                else:
                    if 0 < m and j+m <= n-1:
                        r[j+m] += 1
                    elif m < 0 and 0 <= j+m:
                        r[j+m] += 1
    l = copy(r)

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

Submission status: Time Limit Exceeded

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

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

Submission status: 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
        if A[i]==N:
            pass
        else:
            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()))

for l in range(k):
    if a==[n]*n: 
        break
    left_right = [(max(0,i-a[i]), min(n-1,i+a[i]) ) for i in range(n)]
#    print(left_right)
    a=[0]*n
    for i in range(n):
        for j in range(left_right[i][0], left_right[i][1]+1 ):
            a[j]+=1
#     a = [ sum(left_right[j][0]<=i<=left_right[j][1] for j in range(n)) for i in range(n)]

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

for _ in range(K):
  newA=[0]*N
  for i, a in enumerate(A):
    mi=0 if 0>i - a else i-a
    bi=N if N<=i + a+1 else i+a+1
    #print(i,a,mi,bi)
    newA=[j+1 if index>=mi and index<bi else j for index,j in enumerate(newA)]
  A=newA

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a_in = list(map(int, input().split()))
if n <= k:
    for _ in range(n):
        print(n, end= ' ')
    
diff_list = [0 for num in range(n)]
diff_list[0] = a_in[0]
for i in range(1, n):
    diff_list[i] = a_in[i] - a_in[i-1]

for i in range(k):
    new_list = [0 for num in range(n)]
    d_sum = 0
    for j, d in enumerate(diff_list):
        d_sum += d
        if j-d_sum > 0:
            new_list[j-d_sum] += 1
        else:
            new_list[0] += 1
        if d_sum+j+1 < n:
            new_list[j+d_sum+1] -= 1
    # print(new_list)
    diff_list = new_list.copy()

ans = 0
for d in diff_list:
    ans += d
    print(ans, end= ' ')

Submission status: Time Limit Exceeded

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

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

for i in range(len(b)):
    print(b[i],end=' ')

Submission status: Time Limit Exceeded

Solution code:
import math

def pulse_num(n):
    return n + 1
if __name__ == "__main__":
    N, K= list(map(int, input().split()))
    A = list(map(int, input().split()))

    if N-1 <= K:
        A = [N] * len(A)
    else:
        for k in range(K):
            B = [1] * len(A)
            for i in range(N):
                if A[i] != 0:
                    if i - A[i] - 0.5 < 0:
                        low = 0
                    else:
                        low = math.ceil(i - A[i] - 0.5)
                    if i + A[i] + 0.5 > N - 1:
                        high = N - 1
                    else:
                        high = math.floor(i + A[i] + 0.5)
                    B[low:high+1] = list(map(pulse_num, B[low:high+1]))
                    B[i] -= 1
            A = B

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

Submission status: Time Limit Exceeded

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

for k in range(K):
  llist = []
  B = [0]*N
  for i, a in enumerate(A):
    l = list(range(i-a+1, i+a+2))
    llist.extend(l)
  for i in range(len(A)):
    A[i] = llist.count(i+1)

print(*A)

Submission status: Time Limit Exceeded

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

def changeLamp(lampList):
    newLampList = [0] * len(lampList)
    for i in range(len(lampList)):
        curLampStr = lampList[i]
        rangeLeft = math.ceil(i - curLampStr - 0.5)
        rangeLeft = rangeLeft if rangeLeft>=0 else 0
        rangeRight = int(i + curLampStr + 0.5)
        rangeRight = rangeRight if rangeRight<=len(lampList)-1 else len(lampList)-1
        newLampList = newLampList[:rangeLeft] + [x+1 for x in newLampList[rangeLeft:rangeRight+1]] + newLampList[rangeRight+1:]

    return newLampList

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

lampList = [int(x) for x in input().split()]
for i in range(k):
    lampList = changeLamp(lampList)
    if lampList[0] == lampList[-1] and lampList[0] == len(lampList):
        break

for lamp in lampList:
    print(lamp, end=' ')

Submission status: Time Limit Exceeded

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

for z in range(K):
  #print("############### ",z+1,"回目 #############")
  #A_range = list() #照らしてる範囲のリスト
  i_count = [0]*len(A) #座標iを照らすライトの数
  for i in range(1,len(A)+1):
    #i_range = list() #i番目のライトが照らす範囲
    light = A[i-1]
    #print("ライト",i,"の明かりの強さ",light)
    #i_range = [i - light - 0.5,i + light + 0.5]
    #A_range.append(i_range)
    for x in range(i-light,i+light+1):
      if x >= 1 and x <= len(A):
        #print(x)
        i_count[x-1] += 1
        #print("i_count:",i_count)
  A = i_count
for i in range(len(A)):
  print(A[i], end=' ')

Submission status: Time Limit Exceeded

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n, k, *a = map(int, read().split())

if k >= (n//2)+2:
    b = [n] * n
    print(*[b[i] for i in range(n)])
    exit()

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

print(*[b[i] for i in range(n)])

Submission status: Time Limit Exceeded

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

for l in range(k):
    a2 = [0]*n
    for m in range(n):
        if (a[m] == 0):
            a2[m] += 1
            continue
        start = max(m-a[m],0)
        end   = min(m+a[m]+1,n)
        for o in range(start, end):
            a2[o] +=1
    a = a2

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