Problem:


Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.
Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 2 \times 10^5

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2 

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3 



Sample input:
5 1
1 0 0 1 0


Sample output:
1 2 2 1 2

Submission status: Time Limit Exceeded

Solution code:
import 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//2 + 1:
    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//2):
            if A[j] >= length-(j+1):
                zero += 1
            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
        for j in range(N//2, N):
            if A[j] >= j:
                zero += 1
            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
        if count == 0:
            break
        else:
            A = zero

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

Submission status: Time Limit Exceeded

Solution code:
N,K=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):
    B=[0]*N
    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:
N,K=map(int,input().split())
a = list(map(int,input().split()))
b=[0]*len(a)
for k in range(K):
    b=[0]*len(a)
    for i,fac in enumerate(a):
        b[i]+=1
        if i==0:
            for j in range(fac):
                if (i+j+1)<=N-1:
                    b[i+j+1]+=1
        elif i+1==N:
            for j in range(fac):
                if (i-j-1)>=0:
                    b[i-j-1]+=1
        else:
            for j in range(fac):
                if (i+j+1)<=N-1:
                    b[i+j+1]+=1
                if (i-j-1)>=0:
                    b[i-j-1]+=1
    a=b
a=[int(c) for c in a]
a=[str(c) for c in a]
a=' '.join(a)
print(a)

Submission status: Time Limit Exceeded

Solution code:
import copy

#f = open('./input_C.txt')
#N,K = map(int, f.readline().split())
#A0 = list(map(int, f.readline().split()))

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

B = A0
for i in range(K):
    A = copy.deepcopy(B)
#    B = np.zeros(N)
    B = [0 for _ in range(N)]
#    B = B.astype("int32")
    for j in range(N):
        for k in range(max(0,j-A[j]),min(N,j+A[j]+1)):
            B[k]+=1

#anslist = B.tolist()
ans = ""
for ans_i in B:
    ans+=str(ans_i)+" "
ans = ans[:-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10 ** 7)

N, K = map(int, input().split())
# A = np.array(list(map(int, (input().split()))))
A = list(map(int, (input().split())))
# nd = np.zeros((N,N), dtype=bool)
# print(*A)
for i in range(min(K,1000)):
    cnt = [0]*N
    for j in range(N):
        # nd[j, max(j-A[j],0):min(j+A[j]+1,N)] = True
        for k in range(max(j-A[j],0), min(j+A[j]+1,N)):
            cnt[k] += 1
    # print(nd)
    A = copy.copy(cnt)

print(*A)

Submission status: Time Limit Exceeded

Solution code:
import math

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

for i in range(k):
    b = [0 for z in range(n)]
    for j in range(n):
        start = math.ceil(j-a[j]-0.5)
        end = math.floor(j+a[j]+0.5)+1

        for lit in range(max([0, start]),min([end, n])):
            b[lit] += 1
    a = b

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

Submission status: Time Limit Exceeded

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

def ligh(li):
  for x in range(k):
    if li==[n]*n:
      return li
    ne=[0]*n
    ar=[]
    for (i,a) in zip(range(n),li):
      for j in range(max(0,i-a),min(i+a+1,n)):
        ne[j]+=1
    li=ne
    #print(li)
  return li

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

Submission status: Time Limit Exceeded

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

for x in range(K):
  lis = []
  for i in range(N):
    n = 0
    for j in range(N):
      if A[j]-abs(i-j) >= 0:
        n += 1
    lis.append(n)
  A = lis
    
A = [str(a) for a in A]
A = " ".join(A)
print(A)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int, input().split())
if k>=n:
    a=[n]*n
    print(*a)
    exit()
a=list(map(int, input().split()))

class segtree:
    x_unit=0 # 要素として入れられる最大値
    def __init__(self,N):
        self.n=(1<<len(bin(N-1)[2:]))
        self.x=[self.x_unit]*(2*self.n)

    def build(self, seq):
        for i,j in enumerate(seq, start=self.n):  # n番目からseqをx配列に移していく
            self.x[i] = j
        for i in range(self.n-1, 0, -1):
            self.x[i] = 0
            # セグ木トーナメント表の左右を比較
            # 例えばn=8の時、seq[4]はx[12]に、seq[5]はx[13]に入っている
            # さらにx[14]とx[15]の間に来るのはx[7]、x[12]とx[13]の間に来るのはx[6]

    def fold(self,l,r): # 区間[l, r)値に+1 
        l+=self.n
        r+=self.n-1
        while l<r:
            if l%2==1: # lが奇数
                self.x[l]+=1
                l+=1 # 偶数に調節
            if r%2==0: # rが偶数
                self.x[r]+=1
                r-=1 # 開区間なので1個前は奇数番目の要素
            l //= 2
            r //= 2
        if l==r:
            self.x[l]+=1
        #print(self.x)
    def get(self,i): # seq[i]に対する値を取得 
        i+=self.n
        ret=self.x[i]
        while i>1:
            i //= 2
            ret+=self.x[i]
        return ret

for z in range(k):
    seq=[0]*n
    q=[(max(0, i-a[i]), min(n,i+a[i]+1)) for i in range(n)]
    seg=segtree(n)
    seg.build(seq)
    for i in range(n):
        l,r=q[i]
        seg.fold(l,r)
    ans=[]
    for i in range(n):
        ans.append(seg.get(i))
    a=ans+[]
    if all([i==n for i in a]):
        break
print(*a)

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%2 == 0:
    b = N//2
else:
    b = (N//2) +2
if N==1:
    print(1)
    exit()
if K >= 40:
    for i in range(N-1):
        print(N,end=" ")
    print(N)
    exit()
nextgen2 = [0]*N
for k in range(K):
    nextgen = nextgen2.copy()
    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
s = ' '.join([str(i) for i in A])
print(s)

Submission status: Time Limit Exceeded

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

for k in range(n[1]):
  ans = [0] * n[0]
  for i in range(n[0]):
    s1 = (i + 1) - a[i] - 0.5 # x - d - 0.5
    if 1 > s1:
      s1 = 1
    s2 = (i + 1) + a[i] + 0.5 # x + d + 0.5
    if n[0] < s2:
      s2 = n[0]
    s1 = math.ceil(s1)
    s2 = math.floor(s2) + 1
    for j in range(s1, s2):
      ans[j-1] += 1
  a = ans    

print(*a)

Submission status: Time Limit Exceeded

Solution code:
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n, k = ZZ()
    A = ZZ() + [0]

    for _ in range(k):
        if A[0] >= n+1: break
        nA = [0] * (n+1)
        for i in range(n):
            nA[max(0, i-A[i])] += 1
            nA[min(n, i+1+A[i])] -= 1
        for i in range(1, n+1): nA[i] += nA[i-1]
        A = nA
    print(*A[:-1])

    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
ans = []


def kousin(x, n, d):
    if d < len(ans):
        if x+n < len(ans[0]):
            ans[d][x+n] += 1
            kousin(x+n, ans[d][x+n], d+1)
        

        if x-n >= 0 and n != 0:
            ans[d][x-n] += 1
            kousin(x-n, ans[d][x-n], d+1)
        
    else:
        # print(ans, x, n)
        return

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



for i in range(k):
    ans.append([i]*n)


for i in range(n):
    for j in range(a[i]+1):
        kousin(i,j,0)

r = ''
for i in ans[k-1]:
    r += str(i)
    r += ' '

print(r)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
num = input().split()
num = [int(k) for k in num]
ans =[]
cnt = 0
#電球の個数分0を追加
for i in range (n):
  ans.append(1)
def cal(x):
  for y in range (1,num[x]+1):
  	#　正の方向
  	if x + y <= len(num)-1:
  		ans[x+y] += 1
  	if x - y >= 0:
  		ans[x-y] += 1

#k回繰り返す
for b in range (k):
  #n回電球の強さを適応
  for z in range (n):
    cal(z)
  #最後に全部に一プラス
  #numリストをansに適応
  for z in range(n):
    num[z] = ans[z]
  cnt +=1
  if cnt < k:
    for z in range (n):
      ans[z] = 1

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

Submission status: Time Limit Exceeded

Solution code:
import copy

def main():
    N,K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    for _ in range(K):
        nextA = [1]*N
        for i in range(N):
            # print(max(0,i-A[i]),min(i+A[i],N))
            for j in range(max(0,i-A[i]),min(i+A[i]+1,N)):
                if i == j:
                    continue
                nextA[j] += 1
                # print(i,j,A[i],nextA)
        A = copy.copy(nextA)
    print(' '.join([str(a) for a in nextA]))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

note = [[0 for _ in range(N)] for _ in range(K+1)]
note[0] = l

for i in range(K):
    for j in range(N):
        for k in range(max(0,j-note[i][j]),min(N-1,j+note[i][j])+1):
            note[i+1][k] += 1
print(*note[-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np                       
                                         
N,K,*A = map(int, open(0).read().split())
                                         
for _ in range(K):                       
    X = np.ones(N, int)                  
    for i, d in enumerate(A):            
        X[max(0,i-d):max(0,i)] += 1      
        X[i+1:i+d+1] += 1                
    A = X                                
                                         
print(" ".join(map(str, A)))

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 i in range(K):
  B= [0 for _ in range(N)]
  C=0
  for j in A:

    if(C-j<0):
      left=0
      B[left]+=1
    else:
      left=C-j
      B[left]+=1
    if(C+j+1>=N):
      right=N-1
    else:
      right=C+j+1
      B[right]-=1

    C+=1
  
  ruiseki = [0] * N  # 累積和用リスト
  ruiseki[0] = B[0]
  for m in range(N):
      ruiseki[m] = ruiseki[m-1] + B[m]
  A = copy.copy(ruiseki)
print(*ruiseki)

Submission status: Time Limit Exceeded

Solution code:
def draft(A, K, N):
    for _ in range(1, K+1):# 2 * 10**5
        tmp = [0]*(N+1)
        for i in range(N):# 2 * 10**5
            L = max(0, i - A[i])
            R = min(N, i + A[i]+1)
            tmp[L] += 1
            tmp[R] -= 1
        for i in range(N):
            tmp[i+1] += tmp[i]
            A[i] = tmp[i]
    for i in range(N):
        print(A[i], end=" ")

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

if __name__ == "__main__":
    main()

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

import numpy as np
for _k in range(k):
  arr_left = np.zeros(0)
  arr_right = np.zeros(0)
  result = np.zeros(n)
  result_right = np.zeros(n)  
  for i in range(n):
    arr_left = np.append(arr_left, a[i])
    arr_right = np.append(arr_right, a[n-i-1])
    result[i] = sum(arr_left >= 0)
    result_right[n-i-1] = sum(arr_right >= 0)
    arr_left -= 1
    arr_right -= 1
  a = result + result_right -1
ans = ""
for i in list(a):
  ans += str(int(i)) + " "
print(ans[0:-1])

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 >= 100:
    b = [n] * n
    print(*[b[i] for i in range(n)])
    exit()

for q 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
    
    if b == [n] * n:
        break
    else:
        a = b

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

Submission status: Time Limit Exceeded

Solution code:
def flip(arr):
    newArr=[0]*(len(arr)+1)
    for i in range(len(arr)):
        b=i-arr[i]
        e=i+arr[i]
        newArr[max(0,b)]+=1
        newArr[min(len(arr),e+1)]-=1
    for i in range(1,len(arr)+1):
        newArr[i]+=newArr[i-1]
    newArr.pop(len(arr))
    return newArr

a=input().split()
k=int(a[1])
arr=input().split()
arr=list(map(int,arr))
for i in range(k):
    arr=flip(arr)
arr=list(map(str,arr))
print(" ".join(arr))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

def kakou(arr):
    if sum(arr) == len(arr)**2:
        return arr
    terasare = [0]*len(A)
    for i, value in enumerate(arr):
        for a in range(i-value,i+value+1):
            if a<0 or a > len(arr)-1:
                continue
            terasare[a] += 1
    return terasare

temp = A

for x in range(K):
    temp = kakou(temp)

print(*temp)

Submission status: Time Limit Exceeded

Solution code:
N,K= map(int,input().split())
A = list(map(int,input().split()))
for t in range(K):
    T = [0]*N
    for i in range(N):
        for j in range(i-A[i],i+A[i]+1):
            if j>=0 and j<=N-1:
                T[j] += 1
    if A == T:
        break
    A = T
print(' '.join(map(str,A)))

Submission status: Time Limit Exceeded

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

B = [[0] * N for _ in range(K + 1)]
B[0] = A[:]

for i in range(K):
    for j in range(N):
        d0 = int(j - B[i][j])
        if d0 < 0: d0 = 0
        d1 = int(j + B[i][j])
        if d1 >= N: d1 = N - 1

        for k in range(d0, d1 + 1):
            B[i + 1][k] += 1  

ans = ' '.join(map(str, (B[-1])))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def print_list(xs):
    print(" ".join([str(x) for x in xs]))

def resolve():
    N, K = [int(i) for i in input().split()]
    A_list = [int(i) for i in input().split()]
    if N <= K:
        print_list([N] * N)
        return
    for i in range(K):
        light_list = [0] * N
        for j in range(len(A_list)):
            for k in range(-A_list[j], A_list[j]+1):
                light_list += np.eye(1, N, k=j+k, dtype=int)
        A_list = light_list.reshape(N)
    print_list(A_list)

resolve()

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,i8


@njit(i8[:](i8,i8,i8[:]))
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 sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
a = na()


for p in range(k):
    b = [0]*n
    for i in range(n):
        k = i+a[i]+1
        w = i-a[i]
        if k < n:
            b[k] -= 1
        if 0 <= w:
            b[w] += 1
        else:
            b[0] += 1

    for j in range(1,n):
        b[j] = b[j]+b[j-1]
    a = b

print(*a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

  if cnt == k:
    break

  ans *= 0
  x_left = l-d
  x_left[x_left < 0] = 0
  x_right = l+d+1
  x_right[x_left > n] = n
  func(x_left, x_right)
  cnt += 1
  d = ans.copy()

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

Submission status: Time Limit Exceeded

Solution code:
class DualSegTree():
    def __init__(self,n):
        self.n=n
        self.data=[0]*n*2
    def propagate(self,i):
        if i>=self.n*2:return
        data=self.data
        c,j=0,i
        while j:
            j>>=1
            c+=1
        for j in range(c-1,0,-1):
            j=i>>j
            data[j+j]+=data[j]
            data[j-~j]+=data[j]
            data[j]=0
    def update(self,l,r,x):
        data=self.data
        l+=self.n
        r+=self.n
        self.propagate(l)
        self.propagate(r)
        while l<r:
            if l&1:
                data[l]+=x
                l+=1
            if r&1:
                r-=1
                data[r]+=x
            l>>=1
            r>>=1
    def get(self,i):
        i+=self.n
        self.propagate(i)
        return self.data[i]
def main():
    n,k,*a=map(int,open(0).read().split())
    seg=DualSegTree(n)
    seg.data[n:]=a
    for _ in range(k):
        d=DualSegTree(n)
        get,update=seg.get,d.update
        m=10**18
        for i in range(n):
            t=get(i)
            if t<m:m=t
            update(max(0,i-t),min(i-~t,n),1)
        seg=d
        if m==n:break
    print(' '.join(str(seg.get(i))for i in range(n)))
main()

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

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

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

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}
del_list = []

for t in range(K):
    if not bulb_to_check:
        break
    for i in bulb_to_check:  # i番目の電球の明るさを決定する
        for j in range(N):  # 各電球jが、電球iを照らしているかを確認する
            if j - A[j] - 0.5 <= i <= j + A[j] + 0.5:
                count += 1
        tmp[i] = count
        if tmp[i] == N:
            del_list.append(i)
        count = 0
    for bulb in del_list:
        del bulb_to_check[bulb]  # 最大値に達した電球を対象から除く
    for l in bulb_to_check:
        A[l] = tmp[l]

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()))
a = np.asarray(a, dtype=int)
if k<n:
    for i in range(k):
        b = np.zeros(n, dtype=int)
        for j in range(n):
            mi = j-a[j]
            ma = j+a[j]
            if mi<0:
                mi = 0
            if ma>=n:
                ma = n-1
            b[mi:ma+1]+=1
        a = b
        if np.mean(a)==n:
            break
else:
    for i in range(n):
        a[i] = n
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import copy
N,K = map(int,input().split())
A = list(map(int,input().split()))
#B = copy.copy(A)
#B = [0 for _ in range(N)]
for t in range(K):
  while min(A) >= N:
    ans = [N]*N
    print(*ans)
    exit()
  B = [0 for _ in range(N)]
  for i in range(N):
    MIN = max(0,i-A[i])
    MAX = min(N-1,i+A[i])
    p = MIN
    while p<=MAX:
      B[p] +=1
      p += 1
  A = B
  #print(B)
print(*B)

Submission status: Time Limit Exceeded

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

        b = list(range(int(i - a[i]), int(i + a[i] + 1)))
        for j in b:
            if j < 0 or j >= len(a):
                q = 0
            else:
                a_new[j] += 1
    a = a_new
for i in a:
    print(int(i))

Submission status: Time Limit Exceeded

Solution code:
import copy
n,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
# ans=[0 for i in range(n)]
end=0
cnt=0
flag=0
for i in range(k):
  l=[]
  now=[0 for m in range(n)]
  for j in range(n):
    d=a[j]
    ll=j-d
    rr=j+1+d
    if ll<=0:
      ll=0
    if n<=rr:
      rr=n
    l.append([ll,rr])
  for s,e in l:
    cnt=0
    for c in range(s,e):
      now[c]+=1
      if n-1<=now[c]:
        cnt+=1
    if cnt==n-1:
      flag=1
  a=copy.deepcopy(now)
  if flag==1:
    end=i
    break

if flag==1:
  for i in range(n):
    a[i]+=k-end

print(*a)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
num = input().split()
num = [int(k) for k in num]
ans =[]
cnt = 0
#電球の個数分0を追加
for i in range (n):
  ans.append(0)
def cal(x):
  for y in range (1,num[x]+1):
  	#　正の方向
  	if x + y <= len(num)-1:
  		ans[x+y] += 1
  	if x - y >= 0:
  		ans[x-y] += 1

#k回繰り返す
for b in range (k):
  #n回電球の強さを適応
  for z in range (n):
    cal(z)
  #最後に全部に一プラス
  for a in range (n):
  	ans[a] +=1
  #numリストをansに適応
  for z in range(n):
    num[z] = ans[z]
  cnt +=1
  if cnt < k:
    for z in range (n):
      ans[z] = 0

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

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
if((n+3)//2+1 <= k):
    c = [str(n)]*n
else:
    for i in range(k):
        b = [0]*n
        p = 0
        for j in range(n):
            if(a[j] == n):
                p += 1
            else:
                for k in range(max(0,j-a[j]),min(n-1,j+a[j])+1):
                    b[k] += 1
        if(p == n):
            c = [str(n)]*n
            break
        else:
            for k in range(n):
                b[k] += p
            a = b
    c = [str(a) for a in b]
print(' '.join(c))

Submission status: Time Limit Exceeded

Solution code:
def light(li,number):
  lis = []
  for i in range(number):
    n = 0
    for j in range(number):
      if li[j]-abs(i-j) >= 0:
        n += 1
    lis.append(n)
  li = lis
  return li

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

for x in range(K):
  A = light(A,N)
  
A = [str(a) for a in A]
A = " ".join(A)
print(A)

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)]
init_light = [0 for i in range(n)]
for i in range(k):
  number_light = init_light
  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)])))
      #number_light = list(np.array(number_light)+np.array([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:
    break
print(*light_power)

Submission status: Time Limit Exceeded

Solution code:
import copy
#貪欲じゃダメ？→ダメでした(それはそう)
n,k=map(int,input().split())
A=list(map(int,input().split()))
#イメージ的には真ん中へんからマックスになって
#最終的には全部マックスになるイメージ
#そういや全部ゼロなら一生動かないな
#全部マックスでも一生動かないけど
pA=[-1]*n
B=[0]*n
for z in range(k):
  for i in range(n):
    d=A[i]
    pd=pA[i]
    if pd!=-1:
      if d!=pd:
        #違うってことは延びてる
        for j in range(d-pd):
          if i-d+j>=0:
            B[i-d+j]+=1
          if i+d-j<n:
              B[i+d-j]+=1
    else:
      for j in range(2*d+1):
        if i-d+j>=0 and i-d+j<n:
          B[i-d+j]+=1
  pA=A
  A=copy.deepcopy(B)
print(*A)

Submission status: Time Limit Exceeded

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

    for _ in range(K):
        Bs = [0] * N
        for i, A in enumerate(As):
            for j in range(i-A, i+A+1):
                if 0 <= j <= N-1:
                    Bs[j] += 1
        As = Bs
        num = As.count(N)
#        print('\n_:', _, '/ num:', num)
#        print('As:', As)
        if num == N:
            break

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


solve()

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().rstrip().split(" "))
A = [list(map(int,input().rstrip().split(" ")))]
imos = [0 for i in range(N + 1)]
P = 0
flag = True
counter = 0
while flag:
    A.append([0 for i in range(N)])
    P = 0
    for i in range(N+1):
        imos[i] = 0
    for i in range(N):
        imos[max(0,i - A[counter][i])] += 1
        imos[min(N,i + A[counter][i] + 1)] -= 1
    if imos[0] == N and imos[N] == -1 * N:
        flag = False
    for i in range(N):
        P += imos[i]
        A[counter + 1][i] = P
    counter += 1
    if counter == K:
        break
print(" ".join(map(str,A[-1])))