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):
    cnt=[0]*N
    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 i in range(k):
    tmp = [0] * n
    for j in range(n):
        for k in range(a[j]*2+1):
            if (j - a[j] + k) >= 0 and (j - a[j] + k) < n:
                tmp[(j - a[j] + k)] += 1
    
    if min(a) == n:
        print(' '.join(map(str, a)))
        exit()
    a = tmp


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


# 10 5
# 20 8
# 40 10
# 80 12
# 160 15

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

INF = 2**31-1


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


class RangeUpdate:
    def __init__(self, n):
        self.p = Bit(n + 1)
        self.q = Bit(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - self.p.sum(s) - self.q.sum(s) * s


N, k = map(int, input().split())
A = list(map(int, input().split()))
T = RangeUpdate(N)

for j in range(N):
    T.add(j+1, j+1, A[j])
prev_T = T

for i in range(min(k, 3*int(math.log(N))+1)):
    T = RangeUpdate(N)
    for j in range(N):
        num = prev_T.sum(j+1, j+1)
        T.add(max(j - num + 1, 1), min(j + num + 1, N), 1)

    prev_T = T

ans = [0]*N
for i in range(N):
    ans[i] = prev_T.sum(i+1, i+1)

print(*ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for t in range(K):
    for i in range(N):  # i番目の電球の明るさを決定する
        if A[i] == N:
            bulb_finished.append(i)
            del bulb_to_check[i]
        else:
            for j in bulb_to_check:  # 各電球jが、電球iを照らしているかを確認する
                if j - A[j] - 0.5 <= i <= j + A[j] + 0.5:
                    count += 1
            tmp[i] = count
        count = 0
    for l in range(N):
        A[l] = tmp[l]

print(*A)

Submission status: Time Limit Exceeded

Solution code:
import copy
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
        
lo = int(math.log2(n) * 2 + 2)        

k = min(lo, k)

for i in range(k):
    b = [0] * (n + 2)
    
    for m in range(n):
        d = a[m]
        if d > 0:
            if d > m:
                start = 0
            else: 
                start = m - d
                
            if (m + d + 1) > n:
                end = n
            else:
                end = m + d + 1
                
            for j in range(start, end):
                b[j] += 1
        else:
            b[m] += 1
            
        
    a = copy.copy(b)
        
for i in range(n):
    print(a[i], end=" ")

Submission status: Time Limit Exceeded

Solution code:
def get_lump(target_list):
    result_list = [0] * len(target_list)
    for target_num in range(len(target_list)):
        min_range = (target_num + 1) - target_list[target_num] - 0.5
        max_range = (target_num + 1) + target_list[target_num] + 0.5
        for result_num in range(len(result_list)):
            if min_range <= (result_num + 1) <= max_range:
                result_list[result_num] += 1
    return result_list


def main():
    total = list(map(int, input().split()))
    akarusa = list(map(int, input().split()))

    for i in range(total[1]):
        akarusa = get_lump(akarusa)

    kaitou = ''
    for j in range(len(akarusa)):
        if kaitou == '':
            kaitou = str(akarusa[j])
        else:
            kaitou = kaitou + ' ' + str(akarusa[j])

    print(kaitou)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(K):
    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
    As = A0

print(*As,sep=" ")

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,k = inpm()
    a = inpl()
    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 sum(ans) >= n**2:
            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:
n, k = map(int, input().strip().split())
A = list(map(int, input().strip().split()))

# if min(A[0],A[-1])+k
for _ in range(k):
    finish=True
    start=[0]*n
    end=[0]*n
    
    for i in range(n):
        if A[i]!=n:
            finish=False
        start[max(0,i-A[i])]+=1
        end[min(n-1,i+A[i])]+=1
    if finish:
        break
    
    # update ans
    cnt=0
    for i in range(n):
        cnt+=start[i]
        A[i]=cnt
        cnt-=end[i]

print(*A)

Submission status: Time Limit Exceeded

Solution code:
def LI():
    return list(map(int, input().split()))

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

lb = 1
rep = 0
while lb <= 2*n and rep < k:
    lb *= 2
    rep += 1
    b = [0 for i in range(n)]
    for i in range(n):
        for j in range(max(i-a[i], 0), min(i+a[i], n-1)+1):
            b[j] += 1
    a = b.copy()

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

Submission status: Time Limit Exceeded

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

def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A_temp=[0]*N
    for k in range(K):
        for i,data in enumerate(A):
            for j in range(max(0,i-data),min(N,i+data+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 itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K >= 50:
    print(*[N]*N)
    exit()
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
    if A == [N]*N:
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys
n, k = list(map(lambda x: int(x), input().split(" ")))

# only two list object used
blightNess = list(map(lambda x: int(x), input().split(" ")))
cosu = [1] * n

def increment(x, blight):
    left = x - blight if x - blight > 0 else 0
    right = x + blight if x + blight <= n - 1 else n - 1
    for i in range(left, right + 1):
        if i != x:
            cosu[i] = cosu[i] + 1

def operation(cosu, blightNess):
    for i in range(0, n):
        cosu[i] = 1
    for i in range(0, n):
        if blightNess[i] != 0:
            increment(i, blightNess[i])

    return cosu
    
for i in range(0, k):
    cosu = operation(cosu, blightNess)
    tmp = blightNess
    blightNess = cosu
    cosu = tmp

print(" ".join(list(map(lambda x:str(x),blightNess))))

Submission status: Time Limit Exceeded

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

def terasu(a):
    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                
    return(new_a)

for x in range(k):
    a = terasu(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().strip().split()))


def work(list):
    ans=[]
    for i in range(len(list)):
        count=0
        if list[i]==N:
            ans.append(N)
        else:
            for j in range(len(list)):
                if i==j:
                    count+=1
                else:
                    if abs(i-j)<=list[j]:
                        count+=1
            ans.append(count)
    return ans

for i in range(K):
    if i ==0:
        work(A)
        ans=work(A)
    else:
        work(ans)
        if work(ans).count(N)==N:
            break
        else:
            ans=work(ans)

print(*ans)

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())))
length = len(A)
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

if K >= N:
    L=[str(length) for a in range(N)]
    L=" ".join(L)
    print(L)
    exit()
else:
    for i in range(K):
        count = 0
        zero = np.array([0]*N)
        for j in range(N):
            if A[j] == length:
                zero[j] = length
            else:
                count += 1
                if j + A[j] + 1 >= length:
                    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
        A = zero

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

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy

n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*(n+1)
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        st=j-a[j]
        gl=j+a[j]
        if st<0:
            st=0
        if gl>=n:
            gl=n-1
        a1[st]+=1
        a1[gl+1]-=1
    a1=numpy.cumsum(a1)
    a=a1[:n]
    a1=[0]*(n+1)
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()))

if K >= N/2 + 1:
    A= [N]*N
else:
    for _ in range(K):
        B = [0] * N
        for i in range(N):
            if A[i] >= 0:
                if (A[i] >= max(N - i, i)):
                    B = list(map(lambda x: x+1, B))
                else:
                    B[i] += 1
                    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 = copy.copy(B)

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

Submission status: Time Limit Exceeded

Solution code:
x=list(map(int, input().split()))
A=list(map(int, input().split()))
l=[]
for i in range(x[0]):
    l.append(0)

import copy

for p in range(x[1]):
    for i in range(x[0]):
        for j in range(2*A[i]+1):
            if i-A[i]+j>=0 and i-A[i]+j<x[0]:
                l[i-A[i]+j]+=1
    A=copy.deepcopy(l)
    if all(elem ==x[0]  for elem in A)==True:
        break
    l=[]
    for i in range(x[0]):
        l.append(0)
    


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

Submission status: Time Limit Exceeded

Solution code:
import copy
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0 for _ in range(n)]
for v in range(k):
  for i in range(n):
    for j in range(max(1,i+1-a[i]),min(n,i+1+a[i])+1):
      b[j-1]+=1
  
  a=copy.deepcopy(b)
  b=[0 for _ in range(n)]
  
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 k in range(K):
    flag_all = True
    for i in range(N):
        if A[i] != N:
            flag_all = False
    if flag_all:
        break
        
    B = [0] * N
    for i in range(N):
        d = A[i]
        for j in range(-d, d+1):
            index = i + j
            if 0 <= index < N:
                B[index] += 1
    A = B
print(" ".join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


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


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

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

        for j in range(start-1, end):
            B[j] += 1

    A = B

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

Submission status: Time Limit Exceeded

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

for _ in range(k):
    b = [1] * n
    for i in range(n):
        for j in range(1, a[i]+1):
            if i-j >= 0: b[i-j] += 1
            if i+j < n: b[i+j] += 1
    a = deepcopy(b)
    
    if bisect.bisect_left(a, n) == 0: break
        
print(*a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

def main():
    N,K = LI()[:]
    A = LI()
    #print(N,K)
    #print(A)

    for k in range(K):
        B = [0]*N
        for i, a in enumerate(A):
            #print(i, a)
            if a == 0:
                B[i] += 1
            else:
                # i-(a+0.5) ~ i+(a+0.5)
                # i: 整数、a: ＋整数　なので +0.5 は切り捨てられる。
                #　影響範囲は、 i-a ~ i+a
                for p in range(i-a,i+a+1):
                    #print("p:",p)
                    if p >=0 and p < N:
                        B[p] += 1
                #print(B)
        if k < K-1:
            A = B

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

num_of_lamps, num_of_operation = map(int, input().split())
intensitys = 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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

dic = {}
for i, j in enumerate(A, 1):
    dic[i] = j

for l in range(K):

    dic_copy = dic.copy()
    for i in range(1, N + 1):
        dic[i] = 0

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

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

    input_list = tmp_list

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

Submission status: Time Limit Exceeded

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

max_power = [n for i in range(n)]
for i in range(k):
  number_light = [0 for i in range(n)]
  for j,_power in enumerate(light_power):
    if _power == 0:
      number_light[j] += 1
    else:
      number_light = list(map(sum, zip(number_light, [1 if i>=(j+1-_power-0.5) and (j+1+_power+0.5)>=i else 0 for i in range(1,n+1)])))
  light_power = number_light
  if light_power == max_power:
    print(i)
    break
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()))


def a_to_b(A):
    c = [0] * N
    for i, a in enumerate(A):
        lb = max(0, i - a)
        c[lb] += 1
        ub = i + a + 1
        if ub < N:
            c[ub] -= 1
    tmp = 0
    B = []
    for ci in c:
        tmp += ci
        B.append(tmp)
    return B


ans = A
for _ in range(K):
    ans = a_to_b(ans)

print(*ans)
pass

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[:]
print(*arr)

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 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]))
    print(ans2)

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy
def update(a):
    b = np.zeros(len(a), dtype=np.int)
    for i, v in enumerate(a):
        strength = v # 2とか
        # print("strength:", strength)
        start = max(i - strength, 0) # 0 - 2 = -2
        end = min(i + strength + 1, len(a)) # 0 + 2 + 1 = +3
        b[start:end] = b[start:end] + 1
        # print("b:",b)
    return b

n, k = (int(n) for n in input().split())
a = np.array([int(n) for n in input().split()], dtype=np.int)

for i in range(k):
    a = update(a)

# print(a)
result = ""
for v in a:
    result += str(v) + " "
result = result[:-1]
print(result)

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import numpy as np

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,k=map(int, readline().rstrip().split())
    arr=list(map(int, readline().rstrip().split()))

    for _ in range(k):
        tmp=[0]*n
        for i in range(n):
            x = i - arr[i]
            y = i + arr[i] + 1
            if x<0:
                x=0
            if y<n:
                tmp[y]-=1
            tmp[x]+=1
        arr[0]=tmp[0]
        for i in range(1,n):
            arr[i]=arr[i-1]+tmp[i]
    print(" ".join(map(str,arr)))
    return

    xxx="2 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0"
    arr=list(map(int, xxx.rstrip().split()))
    n=len(arr)
    k=10

    for _ in range(k):
        tmp=[0]*n
        for i in range(n):
            x = i - arr[i]
            y = i + arr[i] + 1
            if x<0:
                x=0
            if y>n:
                y=n
            for j in range(x,y):
                tmp[j]+=1
        arr=tmp
        print(arr)

    arr=list(map(int, xxx.rstrip().split()))
    n=len(arr)
    print("---")
    tmp=[0]*n
    for i in range(n):
        x = i - arr[i]
        y = i + arr[i] + 1
        if x<0:
            x=0
        if y>n:
            y=n
        for j in range(x,y):
            tmp[j]+=1
    arr=tmp
    print(arr)
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    arr=list(map(int, xxx.rstrip().split()))
    n=len(arr)
    print("---")
    tmp=[0]*n
    for i in range(n):
        x = i - arr[i]
        y = i + arr[i] + 1
        if x<0:
            x=0
        if y<n:
            tmp[y]-=1
        tmp[x]+=1
    arr=list(np.cumsum(tmp))
    print(arr)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
temp=[0]*len(a)
ans=[0]*len(a)
for i in range(len(a)*k):
    i=i%len(a)
    left=0
    right=0
    if a[i]==0:
        temp[i]+=1
    else:
        left=i-a[i]
        right=i+a[i]
        if left<=0:
            left=0
        if len(a)-1<right:
            right=len(a)-1
        for j in range(left,right+1):
            temp[j]+=1
    if i==len(a)-1:
        ans=temp 
        a=temp
        temp=[0]*len(a)
print(*ans)

Submission status: Time Limit Exceeded

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

t = 0
while t < k:
  tmpds = [0] * n
  i = 0
  while i < n:
    j = max(i - ds[i], 0)
    while j <= i + ds[i]:
      if j >= n:
        break
      tmpds[j] += 1
      j += 1
    i += 1
  ds = tmpds.copy()
  if ds.count(n) == n:
    break
  t += 1

dsstr = map(str, ds)
ans = " ".join(dsstr)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(K):
    B = [0 for k in range(N)]
    for j in range(N):
        L = A[j]
        for k in range(max(j-L, 0), min(j+L+1, N)):
            B[k] += 1
    A = copy.deepcopy(B)
    if len(set(A)) == 1 and A[0] == N:
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, k = inpl()
a = inpl()
dp = [(0, 0)] * n
for j in range(k):
    for i in range(n):
        l = max(0, i - a[i])
        r = min(n - 1, i + a[i])
        dp[i] = (l, r)
    imos = [0] * n
    for i in range(n):
        l, r = dp[i]
        imos[l] += 1
        if r < n - 1:
            imos[r + 1] -= 1
    tmp = 0
    FLAG = True
    for i in range(n):
        tmp += imos[i]
        if tmp != n - 1:
            FLAG = False
        a[i] = tmp
    if FLAG:
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
#from numba import jit
N , K = map(int,input().split())
C = list(map(int,input().split()))
#@jit
def solve(C,N,K):
  A = C
  for j in range(K):
    B = [0]*N
    d = [0]*(N+1)
    for i in range(N):
      l = max([0 , i - A[i]])
      r = min([N-1 , i+A[i]]) + 1
      d[l] += 1
      d[r] -= 1
    B[0]=d[0]
    for i in range(N-1):
      B[i+1] = B[i] + d[i+1]
    A = B
  return(A)
B = solve(C,N,K)
print(' '.join(map(str, B)))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import numpy as np
n, k = map(int, input().split())
a_list = np.array(list(map(int, input().split())))

for i in range(0, k):
    new_a_list = np.array([0] * n)
    for j in range(0, n):
        start = j - a_list[j]
        if start < 0:
            start = 0
        end = j + a_list[j] + 1
        if n < end:
            end = n
        new_a_list[start:end] += 1

    a_list = np.copy(new_a_list)
    if np.all(a_list == n):
      break
for a in a_list:
    print(a, end=" ")

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
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k):
    b = [0] * n
    for j in range(n):
        b[max(0, j - a[j]):min(n, j + a[j] + 1)] = map(lambda x: x + 1, b[max(0, j - a[j]):min(n, j + a[j] + 1)])
    a = b
print(' '.join([str(_) for _ in a]))

Submission status: Time Limit Exceeded

Solution code:
s = input().split()
N = int(s[0]) # 電球の数
K = int(s[1]) # 操作回数

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

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
if N + 2 < K * 2:
    K = int(K/2)
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):
        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)