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

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

    A = b[:-1]
    if all(a == n for a in A):
        break
print(*A)

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):
    imos=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        imos[kagen]+=1
        if jogen+1<n:
            imos[jogen+1]-=1
    akarusanext=imos
    for j in range(1,n):
        akarusanext[j]+=akarusanext[j-1]
    
    if akarusa==akarusanext:
        break
    else:
        akarusa=akarusanext

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
tmp = input().split(' ')
A = []
for i in range(N):
    A = A + [int(tmp[i])]
Z = [N]*N
while K > 0 and A != Z:
    K = K - 1
    B = [0]*N
    for i in range(N):
        l =  max(0,i-A[i])
        r =  min(N-1,i+A[i])
        B[l] = B[l]+1
        if r+1 < N:
            B[r+1] = B[r+1]-1

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

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

Submission status: Time Limit Exceeded

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

def dfs(index, lx):
  if index < 1:
    return lx
  b=[0]*n
  for i in range(n):
    l=max(0,i-lx[i])
    g=min(n-1,i+lx[i])
    b[l]+=1
    if g+1<n:
      b[g+1]-=1
  for i in range(1,n):
    b[i]+=b[i-1]
  return dfs(index-1,b)
    
print(*dfs(min(k,44),a))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = list(map(int, args[1].split()))

    cur = A
    for _ in range(k):
        prev = cur.copy()
        cur = [0]*n
        for x, p in enumerate(prev):
            cur[max(0, x-p)] += 1
            if x+p+1 < n:
                cur[x+p+1] -= 1

        satulated = True
        for i in range(1, n):
            cur[i] += cur[i-1]
            satulated &= cur[i] == n
        if satulated:
            break

    return ' '.join(map(str, cur))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for _ in range(min(K,50)):
    b = np.zeros(N+1, dtype=int)
    for i in range(N):
        l, r = i - A[i], i + A[i] + 1
        if l < 0:   l = 0
        if r > N:   r = N
        b[l] += 1
        b[r] -= 1

    A = np.cumsum(b[:N])

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

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
lamps = list(map(int,input().split()))
for ki in range(k):
    lamplog = [0]*(n+1)
    for i in range(n):
        lamplog[max(0,i-lamps[i])  ] += 1   #先端を出す
        lamplog[min(i+lamps[i]+1,n)] -= 1   #末尾を出す
    # print(lamplog)
    for i in range(n):                      #累積和を計算
        lamplog[i+1] += lamplog[i]
    # print(lamplog)
    lamplog.pop()
    if(lamplog == lamps):                   #１つ前の結果と今回の結果が同じだったら。
        break
    lamps = lamplog                         #今回の結果を記録

ans = ""
for i in range(len(lamplog)):
    ans += str(lamplog[i]) +" "
print(ans.rstrip())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for _ in range(min(K,50)):
    b = np.zeros(N+1)
    for i in range(N):
        l, r = i - A[i], i + A[i] + 1
        if l < 0:   l = 0
        if r > N:   r = N
        b[l] += 1
        b[r] -= 1

    A = list(map(int, np.cumsum(b[:N])))

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

Submission status: Time Limit Exceeded

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

def r(i,a):
    x1=i+1-a
    x2=i+2+a
    return [l for l in range(x1,x2) if(l>0 and l-1<N)]

for k in range(K):
    if(k>42):
        break
    B=np.zeros(shape=N,dtype=np.int64)
    for i in range(N):
        for m in r(i,A[i]):
            B[m-1]+=1
    A=B
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import numpy as np
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    for m in range(k):
        B = np.zeros(n + 1, dtype=np.int64)
        for i in range(n):
            l = max(0, i - A[i])
            r = min(n, i + A[i] + 1)
            B[l] += 1
            if r < n:
                B[r] -= 1
        A = np.cumsum(B)[:-1]
        if np.all(A == n):
            break

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

resolve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
#input→sys.stdin.readline半分の時間に
input=sys.stdin.readline

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

elif K > 50:
    K = 50

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

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

Submission status: Time Limit Exceeded

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

if(n<k):
    for i in range(n):
        print(n,end=" ")

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


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

Submission status: Time Limit Exceeded

Solution code:
n, K = map(int,input().split())
A = list(map(int,input().split()))
b = [0 for _ in range(n+1)]

for _ in range(K):
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    for i in range(n):
        b[i+1] += b[i]
    A = b[:-1]
    b = [0 for _ in range(n+1)]
    if sum(A) == n*n:
        break
    
print(*A)

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):
    imos=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        imos[kagen]+=1
        if jogen+1<n:
            imos[jogen+1]-=1
    akarusanext=[imos[0]]
    for j in range(1,n):
        akarusanext.append(akarusanext[-1]+imos[j])
    
    if akarusa==akarusanext:
        break
    else:
        akarusa=akarusanext

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

Submission status: Time Limit Exceeded

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

K = min(K,20)
for i1 in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-Lum[i])
        r = min(N-1,i+Lum[i])
        B[l]+=1
        if r+1<N:
            B[r+1]-=1
    for i in range(1,N):
        B[i]+=B[i-1]
    Lum = B
    
Lum = [str(l) for l in Lum]
Lum=" ".join(Lum)
print(Lum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
foo = np.ones((42, N), dtype = "int32")
for k in range(len(A)):
    foo[0][k] = A[k]
if K <42:
    for q in range(K):
        for k in range(N):
            for j in range(1, min(foo[q][k]+1, N-k)):
                foo[q+1][k+j] +=1
            for j in range(1, min(foo[q][k]+1, k+1)):
                foo[q+1][k-j] +=1
        count =0
        for l in range(N):
            if foo[q+1][l] < N:
                break
            else:
                count +=1
        
        if count == N:
            break
        
                        
        #print(foo)
    print(" ".join(map(str, foo[q+1])))

     
else:
    print((str(N)+" ")*(N-1)+str(N))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def update(A, N):
    B = [0] * N
    for i in range(0, N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if (r + 1 < N):
            B[r + 1] -= 1
    return np.cumsum(B)

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for _ in range(0, min(42, K)):
        A = update(A, N)
    print(" ".join([str(item) for item in A]))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

K = min(K,41)
for i1 in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-Lum[i])
        r = min(N-1,i+Lum[i])
        B[l]+=1
        if r+1<N:
            B[r+1]-=1
    for i in range(1,N):
        B[i]+=B[i-1]
    Lum = B
    
Lum = [str(l) for l in Lum]
Lum=" ".join(Lum)
print(Lum)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

# imos法
# log(N)ぐらいで収束するので、打ち切れば計算量的には問題なし？

for i in range(K):
    B = [0] * (N+1)
    for j in range(N):
        l = max(0, j-A[j])
        r = min(j+A[j]+1, N)
        B[l] += 1
        B[r] -= 1
    # print("B: {}".format(B))
    for j in range(N):
        B[j+1] += B[j]
    del B[N]
    # print("B: {}".format(B))
    if A == B:
        break
    A = copy.deepcopy(B)

print(*A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
#input→sys.stdin.readline半分の時間に
input=sys.stdin.readline

# = 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 > 50:
    K = 50

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, K = MI()
    A = LI()
    for i in range(K):
        B = [0] * N
        for idx, a in enumerate(A):
            l = max(0, idx - a)
            r = idx + a + 1
            # print(idx, a, l, r)
            B[l] += 1
            if N > r:
                B[r] -= 1
        # print(B)
        B = list(accumulate(B))
        # print(B)
        if A == B:
            printlist(A)
            return
        A = B
    printlist(A)



if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for _ in range(K):
    _A = np.zeros(N + 1, dtype=np.int64)
    
    for i, a in enumerate(A):
        idx_st = max(0, i - a)
        idx_end = min(N, i + a + 1)

        _A[idx_st] += 1
        _A[idx_end] -= 1
    A = np.cumsum(_A)[:-1]
    if np.all(A == N):
        break
    
print(*A)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    _max = max
    _min = min
    for _ in range(k):
        C = [0] * n
        for i in range(n):
            a = A[i]
            l = _max(0, i - a)
            r = _min(n, i + a + 1)
            C[l] += 1
            if r < n:
                C[r] -= 1
        r = 0
        for i in range(n):
            r += C[i]
            A[i] = r
        if A == [n] * n:
            break
    print(" ".join(map(str, A)))
main()

Submission status: Time Limit Exceeded

Solution code:
n,k = input().split(' ')
N =int(n)
K =int(k)
kara =[]
graph = input().split(' ')

for i in range(N):
    g = int(graph[i])
    
    kara.append(g)


def sense(num):
    shake =[]
    for d in range(N):
      
        shake.append(0)
    for s in range(1,N+1):
        for z in range(1,N+1):
            if s - num[s-1]-1 < z < s+num[s-1] +1:
                
                shake[z-1] +=1
                
    return shake

  
for t in range(K):
    right =sense(kara)
    
    kara = right
    
for c in kara:
    print(c,end=' ')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
foo = np.ones((42, N), dtype = "int64")
for k in range(len(A)):
    foo[0][k] = A[k]
if K <42:
    for q in range(K):
        for k in range(N):
            for j in range(1, min(foo[q][k]+1, N-k)):
                foo[q+1][k+j] +=1
            for j in range(1, min(foo[q][k]+1, k+1)):
                foo[q+1][k-j] +=1
        count =0
        for l in range(N):
            if foo[q+1][l] < N:
                break
            else:
                count +=1
        
        if count == N:
            break
        
                        
        #print(foo)
    print(" ".join(map(str, foo[q+1])))

     
else:
    print((str(N)+" ")*(N-1)+str(N))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
n, K = map(int,input().split())
A = list(map(int,input().split()))
b = [0 for _ in range(n+1)]

for _ in range(K):
    for i,a in enumerate(A):
        b[max(0, i-a)] += 1
        b[min(n, i+a+1)] -= 1

    ac = list(accumulate(b))
    A = ac[:-1]
    b = [0 for _ in range(n+1)]
    if sum(A) == n*n:
        break
    
print(*A)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    _max = max
    _min = min
    for _ in range(k):
        C = [0] * n
        for i in range(n):
            a = A[i]
            l = _max(0, i - a)
            r = _min(n, i + a + 1)
            C[l] += 1
            if r < n:
                C[r] -= 1
        r = 0
        for i in range(n):
            r += C[i]
            A[i] = r
    print(" ".join(map(str, A)))
main()

Submission status: Time Limit Exceeded

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


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

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


n, k = xnxn()
a = np.array(xnxn(flag="l"))
for _ in range(k):
    tmp = np.zeros(n, dtype="int")
    for i in range(0, n):
        idx_min = max(0, i - a[i])
        idx_max = min(n-1, i + a[i])
        tmp[idx_min:idx_max+1] = tmp[idx_min:idx_max+1]+1
    if np.all(a == tmp):
        break
    a = tmp

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n, k = map(int, input().split())
    k = min(100, k)
    A = list(map(int, input().split()))
    for m in range(k):
        B = [0 for i in range(n + 1)]
        for i in range(n):
            l = max(0, i - A[i])
            r = min(n, i + A[i] + 1)
            B[l] += 1
            if r < n:
                B[r] -= 1

        for i in range(1, n):
            B[i] += B[i - 1]

        if A == B:
            break
        A = B[:n]

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

resolve()

Submission status: Time Limit Exceeded

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

def all_n(array):
    for i in range(n):
        if array[i]!=n:
            return False
    return True

for _ in range(k):
    if all_n(a):
        break
    temp = [0]*n
    for i in range(n): #imos法
        left, right = max(0,i-a[i]), min(i+a[i],n-1)
        temp[left]+=1
        if right+1<n:
            temp[right+1]-=1
    for i in range(n-1):
        temp[i+1]+=temp[i]
    a=temp.copy()
        
for val in a:
    print(val, end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(k):
    b = np.zeros(n, dtype=np.int64)
    for j in range(n):
        lb = max(j - a[j], 0)
        ub = min(j + a[j], n - 1)

        b[lb] += 1
        if ub + 1 < n:
            b[ub + 1] -= 1

    a = b.cumsum()

    if np.all(a == n):
        break

print(' '.join(a.astype(str)))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d=[0 for i in range(n)]
c=1
k=min(k,40)

while c<=k:
    b=list(d)
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
        b[i]+=b[i-1]
    c+=1
    a=b

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

Submission status: Time Limit Exceeded

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

if k>100:
    ans=[n]*n
    print(*ans)
    exit()

for _ in range(k):
    pre_cum = [0]*(n+1)
    for i,ai in enumerate(a):
        if i-ai>=0:
            pre_cum[i-ai]+=1
        else:
            pre_cum[0]+=1
        if i+ai<n-1:
            pre_cum[i+ai+1]-=1
        else:
            pre_cum[n]-=1
    a=[]
    tmp=0
    for i in range(n):
        tmp+=pre_cum[i]
        a.append(tmp)

print(*a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for _ in range(K):
    _A = np.zeros(N + 1, dtype=np.int64)
    
    for i, a in enumerate(A):
        idx_st = max(0, i - a)
        idx_end = min(N, i + a + 1)

        _A[idx_st] += 1
        _A[idx_end] -= 1
    A = np.cumsum(_A)[:-1]
    
print(*A)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

    for i in range(K):
        dm = [0]*(N+1)
        for x in range(N):
            dm[max(x - A[x],0)]+=1
            dm[min(x+A[x]+1,N)]-=1
        for j in range(1,N+1):
            dm[j]+=dm[j-1]
        if A[:] == dm[:N]:
            break
        A[:] = dm[:N]
    print(' '.join(map(str,A)))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def next(A):
    t = len(A)
    L = np.zeros(t)
    for i in range(t):
        m = max(0,int(i-A[i]))
        M = min(t,int(i+A[i]+1))
        L[m:M] += np.ones(M-m)
    return L

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

for _ in range(K):
    A = next(A)
    for a in A:
        if a != N:
            break
    else:
        break
A = [str(int(i)) for i in A]
print(" ".join(A))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    for m in range(k):
        B = [0 for i in range(n + 1)]
        for i in range(n):
            l = max(0, i - A[i])
            r = min(n, i + A[i] + 1)
            B[l] += 1
            if r < n:
                B[r] -= 1

        for i in range(1, n):
            B[i] += B[i - 1]

        if A == B:
            break
        A = B[:n]

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

resolve()

Submission status: Time Limit Exceeded

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

    for i in range(K):
        br = np.zeros(N, dtype=np.int64)
        for ind, rux in enumerate(A):
            br[max(ind-rux,0)] += 1
            l = ind+rux+1
            if l < N:
                br[l] -= 1
        A = br.cumsum()

        #X = br.cumsum()
        #A = X[:-1]ボトルネックっぽい
        if br[0] == N and br[-1] == -N:
            print(*A)
            exit()

    print(*A)

if __name__ == "__main__":
    solve()

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

print(*a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def update(A, N):
    B = [0] * N
    for i in range(0, N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        B[l] += 1
        if (r + 1 < N):
            B[r + 1] -= 1
    return np.cumsum(B)

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for _ in range(0, min(100, K)):
        A = update(A, N)
    print(" ".join([str(item) for item in A]))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from numpy import zeros

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

for _ in range(min(K, 41)):
    B = zeros(N, dtype=int)
    for x, d in enumerate(A):
        B[x - d if x > d else 0] += 1
        if (x := x + d + 1) < N:
            B[x] -= 1
    A = B.cumsum()

print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import accumulate
input=sys.stdin.buffer.readline
def int(s):
    a=s[0]-48
    for t in s[1:]:
        a*=10
        a+=t-48
    return a
def main():
    n,k=map(int,input().split())
    a=[*map(int,input().split())]
    for _ in'_'*k:
        b=[0]*n
        for i,t in enumerate(a):
            if(j:=i-t)<0:j=0
            b[j]+=1
            if(j:=i-~t)<n:b[j]-=1
        a=[*accumulate(b)]
        if min(a)==n:break
    print(' '.join(map(str,a)))
main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
#from numba import jit
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a,dtype="int64")

#@jit
def imo(a):
    imos=np.zeros(n+1,dtype="int64")
#print(arr[0])
    for i in range(n):
        imos[max(0,i-a[i])]+=1
        imos[min(n,i+a[i]+1)]-=1
    
    immo=np.zeros(n+1,dtype="int64")
    immo=np.cumsum(imos)
    return immo[:n]


for _ in range(min(k,41)):
    a=imo(a)
    
print(*a)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    
    for k in range(K):
        next_A = [0 for i in range(N)]
        for i in range(len(A)):
            high = i + A[i] + 1
            if high > N:
                high = N
            low = i - A[i]
            if low < 0:
                low = 0
            for j in range(low,high):
                next_A[j] += 1
        if A == next_A:
            break
        A = next_A
    
    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()))
for _ in range(k):
    C = [0] * n
    for i in range(n):
        a = A[i]
        l = max(0, i - a)
        r = min(n, i + a + 1)
        C[l] += 1
        if r < n:
            C[r] -= 1
    r = 0
    for i in range(n):
        r += C[i]
        A[i] = r
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):
  b=[0]*(n+1)
  for j in range(n):
    b[max(0,j-a[j])]+=1
    b[min(n,j+a[j]+1)]-=1
  for i in range(n):
    b[i+1]+=b[i]
  a=b[:-1]
  if a==[n]*n:exit(print(*a))
print(*a)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    
    for k in range(K):
        next_A = [0 for i in range(N)]
        for i in range(len(A)):
            high = i + A[i] + 1
            if high > N:
                high = N
            low = i - A[i]
            if low < 0:
                low = 0
            for j in range(low,high):
                next_A[j] += 1
        A = next_A
    
    print(*A)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
#input→sys.stdin.readline半分の時間に
input=sys.stdin.readline

# = 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 > 50:
    K = 50

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

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

Submission status: Time Limit Exceeded

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

for _ in range(k):
    new=[0]*n
    for i in range(n):
        for j in range(a[i]):
            if 0<=i-(j+1)<n:
                new[i-(j+1)]+=1
            if 0<=i+(j+1)<n:
                new[i+(j+1)]+=1
    a=[i+1 for i in new]
    if all([i==n for i in a]):
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    
    for k in range(K):
        B = [0 for i in range(N)]
        for i in range(N):
            low = max(0,i-A[i])
            high = min(N-1,i+A[i])
            B[low] += 1
            if high+1 < N:
                B[high+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        if A == B:
            break
        A = B
    
    print(*A)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

while c<=k:
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
        b[i]+=b[i-1]
    c+=1
    a=b

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

Submission status: Time Limit Exceeded

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

print(*A)

Submission status: Time Limit Exceeded

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