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())
l = list(map(int,input().split()))

dp = [[0] * 2 for i in range(n)]

ans = l[:]

for i in range(k):
    for j in range(n):
        dp[j][0] = (j+1 - ans[j] - 0.5)
        dp[j][1] = (j+1 + ans[j] + 0.5)

    ans = [0] * n

    for x in range(n):
        for y in range(n):
            if dp[y][0] <= x+1 <= dp[y][1]:
                ans[x] += 1

else:
    print(*ans)

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

for i in range(NK[1]): # K roop
    B = [0] * len(A)
    for j in range(NK[0]): # N roop
        if A[j]==NK[0]:
            for b in range(len(B)):
                B[b] += 1
            continue

        for k in range(A[j]*2+1):
            if j-A[j]+k >= 0:
                try:
                    B[j-A[j]+k] += 1
                except:
                    break

    for j in range(NK[0]):
        A[j] = B[j]

for i in range(NK[0]):
    print(A[i], " ", 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()))

def ope(A):
    C = np.array([0]*N)
    for i in range(N):
        B = np.array([0]*N)
        B[i:i+A[i]+1] = 1
        for j in range(1,A[i]+1):
            if i - j < 0:
                pass
            else:
                B[i-j:i] = 1
        C = B + C
        B = np.array([0]*N)
    return C

for k in range(1,K+1):
    A = ope(A)

print(*A)

Submission status: Time Limit Exceeded

Solution code:
N, K= map(int,input().split())
A = list(map(int,input().split()))
p=0
while p<K:
  B=[0]*N
  for i in range(N):
    count = 0
    for j in range(N):
      #print(A[j])
      if A[j]+1>abs(j-i):
        count +=1
    #print(["A"]+A)  
    B[i] = count
    #print(["A"]+A)
    #print([B])
  if min(A)==N:
    break
  A = B
  p +=1
print(*A)

Submission status: Time Limit Exceeded

Solution code:
def get_lump(target_list, num):
    result_list = [0] * num
    for target_num in range(len(target_list)):
        min_range = target_num - target_list[target_num] - 0.5
        max_range = target_num + target_list[target_num] + 0.5
        for result_num in range(len(result_list)):
            if min_range < result_num:
                if result_num < max_range:
                    result_list[result_num] += 1
                else:
                    break
    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, total[0])

    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:
N,K=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
A2=A
S=[]
if K>=N//5+5:
    l=list(map(str,[N]*N))
    print(" ".join(l))
    exit()
for i in range(K):
    A=A2
    A2=[0]*N
    for i in range(len(A)):
        d=A[i]
        for j in range(d+1):
            if i-j>=0 and j>0:
                A2[i-j]=A2[i-j]+1
            if i+j<N:
                A2[i+j]=A2[i+j]+1

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

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for x in range(k):
    b = []
    for i,j in enumerate(a):
        b.extend(range(max(i-j,0),min(i+j+1,n)))
    c = collections.Counter(b)
    a = c.values()
    
print(" ".join([str(x) for x in a]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, K = [int(x) for x in input().split()]
lamp_list = np.array(list(map(int, input().split())))

for x in range(K):
    light = np.zeros(N, dtype=np.int)
    for i, lamp_power in enumerate(lamp_list):
        lower = i - lamp_power
        if lower < 0:
            lower = 0
        higher = i + lamp_power + 1
        if higher > N:
            higher = N
        light[lower:higher] += 1
    lamp_list = light

print(" ".join(map(str, list(lamp_list))))

Submission status: Time Limit Exceeded

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

for i in range(K):
  R = [ {} for j in range(N)]

  for j in range(N):
    s = A[j]
    # j - s ~ j + s
    if min(j+s, N-1) in R[max(0, j-s)]:
      R[max(0, j-s)][min(j+s, N-1)] += 1
    else:
      R[max(0, j-s)][min(j+s, N-1)] = 1
        
  # Make Next List
  #print(R)
  B = [0 for j in range(N)]
  L = [0 for j in range(N)]
  t = 0
  for j in range(N):
    r = R[j]
    for k, v in r.items():
      t += v
      L[k] += v
    B[j] = t
    t -= L[j]
    
  #Merge
  A = [ B[j] for j in range(N)]
  if A[0] == N and A[-1] == N:
    for j in range(N):
      if A[j] < N:
        break
    else:
      break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
n, k = [int(s) for s in input().split(" ")]
alist = [int(s) for s in input().split(" ")]

for _ in range(k):
  alist2 = [0 for _ in range(n)]
  for i, a in enumerate(alist):
    for j in range(i - a, i + a + 1):
      if j >= 0 and j < n:
        alist2[j] += 1
  alist = alist2

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

Submission status: Time Limit Exceeded

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

for i in range(K):
  nextA = [0] * N
  for j in range(N):
    lamps = [0] * N
    under, over = 0, N
    if j-As[j] > 0:
        under = j-As[j]
    if j+As[j] < N:
        over = j+As[j]+1
    for k in range(under, over):
        lamps[k] = 1
    nextA = [x+y for x, y in zip(nextA, lamps)]
  As = nextA

ans = ''
for A in As:
    ans += str(A) + ' '
print(ans.strip())

Submission status: Time Limit Exceeded

Solution code:
import copy
import math
 
n,k=map(int,input().split())
a=list(map(int,input().split()))
 
tokuans=[n for i in range(n)]
flag=0
if k>=math.sqrt(2*n)+1:
    a=tokuans
else:
    for i in range(k):
        tmp=[1 for i in range(n)]
        for num, i in enumerate(a):
            if tmp==tokuans:
                flag=1
                break
            for j in range(i):
                j+=1
                if  num+j<n:
                    tmp[num+j]+=1
                if 0<=num-j:
                    tmp[num-j]+=1
        a=tmp
        if flag==1:
            break
 
ans=""
for i in a:
    ans+=str(i)+" "
print(ans[0:-1])

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.insert(0,0)
X = {i:0 for i in range(-2*N,4*N+2)}
k = 0
while k<K:
    for i in range(1,N+1):
        d = A[i]
        X[2*i-2*d-1] += 1
        X[2*i+2*d+1] -= 1
    for i in range(-2*N+1,4*N+2):
        X[i] += X[i-1]
    X[0]=0
    A = [X[2*i] for i in range(N+1)]
    X = {i:0 for i in range(-2*N,4*N+2)}
    if sum(A)==N*N:
        break
    k += 1
print(*A[1:])

Submission status: Time Limit Exceeded

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

# 一度照らされると二度目以降は確実に照らされるはず。
for i in range(K):
    # j番目の電球を操作
    B = np.array([0] * N)
    for j in range(N):
        if A[j] == N:
            B[j] = N
            continue
        maxA = int(j + A[j] + 0.5)
        minA = math.ceil(j - A[j] - 0.5)

        for k in range(max(0, minA), min(N, maxA + 1)):
            B[k] += 1
    A = B.copy()

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

Submission status: Time Limit Exceeded

Solution code:
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, K = LI()
A = LI()


def main():
    ans = A.copy()
    w = [0] * (N + 1)
    for i in range(N):
        w[max(0, i - A[i])] += 1
        w[min(N, i + A[i] + 1)] -= 1
    
    for _ in range(K):
        x = 0
        l = [0] * (N + 1)
        for i in range(N):
            x += w[i]
            ans[i] = x
            l[max(0, i - x)] += 1
            l[min(N, i + x + 1)] -= 1
        w = l
    
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

lamp = []
for i in range(len(A)):
    lamp.append(A[i])


def operation(lampList):
    tmpList = [0] * len(lampList)
    allList = [1] * len(lampList)

    for i in range(len(lampList)):
        l = lampList[i] + 1
        if ((l > NK[0] - i) and (l > i)):
            tmpList = np.array(tmpList) + np.array(allList)
        else:
            tmpList[i] += 1
            for j in range(1, l):
                if (i - j >= 0):
                    tmpList[i - j] += 1
                if (i + j < NK[0]):
                    tmpList[i + j] += 1
    return tmpList

fullList = [NK[0]] * NK[0]
for i in range(NK[1]):
    lamp = operation(lamp)
    if (fullList == lamp):
        break

L=[str(a if a < NK[0] else NK[0]) for a in lamp]
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 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
    A = T
A=' '.join(map(str,A))
print(A)

Submission status: Time Limit Exceeded

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

maximized = []

for k in range(K):
    B = [0] * N

    # 全玉maxになったとき
    if len(maximized) == N:
        break

    for i in range(N):
        # 強さはN超にはならない
        if A[i] == N:
            B[i] = A[i]
            maximized.append(i)
        else:
            # 照らせる範囲
            l = max(0, i - A[i])
            r = min(N - 1, i + A[i])

            for j in range(l, r + 1):
                B[j] += 1
    A = B

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

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[i]
    x2=i+2+A[i]
    X=[]
    for l in range(x1,x2):
        if(l>0):
            X.append(l)
    return X

for k in range(K):
    B=[0]*N
    for i in range(N):
        for m in r(i,A):
            n=m-1
            if(n<N):
                B[n]+=1
    A=B
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

MOD = 10**9 + 7
INF = float('inf')

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

#A = [0 for i in range(N)]
B = [0 for i in range(N)]

# print(A)
for _ in range(K):
    for i in range(N):
        B[i] = 0
    for i in range(N):
        tmp = A[i]
        B[max(i-tmp, 0)] += 1
        idx = min(i+tmp+1, N)
        if idx != N:
            B[idx] -= 1
    # print(B)
    for i in range(N-1):
        B[i+1] += B[i]
    # print(B)
    for i in range(N):
        A[i] = B[i]
    if _ > 2 * int(sqrt(N)):
        break

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

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
count = K
while count > 0:
  B = [0]*N
  for i in range(N):
    a = i-A[i]
    b = i+A[i]
    if N-1-i < A[i]:
      b = N-1
    if i < A[i]:
      a = 0
    c = list(range(a,b+1))
    for j in range(len(c)):
      B[c[j]] += 1
  else:
    count -= 1
    A = B
print(*B)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
def LI():return list(map(int,input().split()))
def yes():print("YES")
def no():print("NO")

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

import numpy as np


for _ in range(k):
    tab=[0]*(n+1)
    for i in range(n):
        q=a[i]
        if 0<=i-q:
            tab[i-q]+=1
        else:
            tab[0]+=1
        if i+q<=n-1:
            tab[i+q+1]-=1
        else:
            tab[n-1+1]-=1
    
    b=np.cumsum(tab)[:n]
    # print(tab,b)
    a=b[:]
print(*a)

Submission status: Time Limit Exceeded

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


for count in range(K):
    B = [0] * N
    for i in range(1,N+1):
        # i - A[i]以上、i + A[i]以下のBの要素に1を足す
        startIndex = i - A[i - 1] - 1
        endIndex = i + A[i -1] - 1
        if startIndex < 0:
            startIndex = 0
        if N < endIndex:
            endIndex = N - 1
        for j in range(N):
            if startIndex <= j and j <= endIndex:
                B[j] = B[j] + 1
    A = B
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())
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:
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
                elif dict[n] == N:
                    temp[n] == N
                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=np.array(list(map(int,input().split())))
ans=a

if k>=n-1:
    print(*[n]*n)
    exit()

L=np.zeros(n,dtype=int)
for i in range(k):
    tmp=np.zeros(n,dtype=int)
    for i in range(n):
        tmp[max(0,i-ans[i]) : min(n,i+ans[i]+1)]+=1
    ans=tmp
print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
life = [[0]*N]*N
#life = [[i==j for i in range(N)] for j in range(N)]
a = list(map(int,input().split()))
for k in range(K):
  life = [[-1*a[j]<=j-i and j-i<=a[j] for j in range(N)]for i in range(N)]
  #print(life)
  a = [sum(life[i]) for i in range(N)]
  #print(life[:][1])
  #print(a)
b=[str(i) for i in a]
b=" ".join(b)
print(b)

Submission status: Time Limit Exceeded

Solution code:
import collections


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

for k in range(K):
    change_list = []
    for i in range(n):
        change_list.extend([j for j in range(1,n+1) if i-a[i]+0.5 < j < i+a[i]+1.5])
    counter = collections.Counter(change_list)
    for m in range(n):
        a[m] = counter[m+1]

ans_list = [str(c) for c in a]
ans=' '.join(ans_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
Aafter=[0]*N
for _ in range(K):
  Arange=[0]*N
  for i in range(N):
    for r in range(max(0,i-A[i]),min(i+A[i]+1,N)):
      Arange[r]+=1
      #print(i,r)
  #print(Arange)
  for i in range(N):
    A[i]=Arange[i]
  pass
print(" ".join(map(str,A)))

Submission status: Time Limit Exceeded

Solution code:
def adjust_light(arr):
    counter = [0] * len(arr)
    
    for idx in range(0, len(arr)):
        min = idx - arr[idx]
        if min < 0:
            min = 0
        max = idx + arr[idx]
        if max >= len(arr):
            max = len(arr)-1
        for position in range(min, max+1):
            counter[position] = counter[position] + 1

    return counter

n, k = list(map(int, input().split(' ')))
arr = list(map(int, input().split(' ')))
for idx in range(0, k):
    arr = adjust_light(arr)
print(*arr)

Submission status: Time Limit Exceeded

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

for m in range(k):
    for i in range(n):
        dum = [i]*n
        b = list(map(lambda x,y,z: x-abs(y-z), a, i_list, dum))
        c[i] = sum(1 for x in b if x >=0)
    a = []
    a += c
a = [str(aa) for aa in a]
print(' '.join(a))

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):
    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()))
s = [1 for i in range(n)]
import copy 
for q in range(min(k,35)):
    ans = copy.deepcopy(s)
    for i in range(n):
        if a[i] != 0:
            ans[i] -= 1
            for j in range(2*a[i]+1):
                if 0 <= i-a[i]+j <= n-1:
                    ans[i-a[i]+j] += 1
    a = ans
g = [0]*n
if k > 34:
    for i in range(n):
        print(g[i], end = ' ')
else:
    for i in range(n):
        print(a[i], end = ' ')

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, heappop

n, k = [int(v) for v in input().split()]
init_lamps = [int(v) for v in input().split()]


def step(lamps):
    if len([0 for v in lamps if v == n]) == n:
        return lamps, True
    new = [1 for _ in range(len(lamps))]
    heap = []
    for i, v in enumerate(lamps):
        while len(heap) > 0 and heap[0] < i:
            heappop(heap)
        new[i] += len(heap)
        if v > 0:
            heappush(heap, i + v)
    heap = []
    for i, v in enumerate(reversed(lamps)):
        while len(heap) > 0 and heap[0] < i:
            heappop(heap)
        new[n - i - 1] += len(heap)
        if v > 0:
            heappush(heap, i + v)
    return new, False


lamps = init_lamps
for _ in range(k):
    lamps, end = step(lamps)
    if end:
        break

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_array = np.array(list(map(int, input().split())))


for k in range(K):

    B_list = list()

    inf_array = np.array(range(N)) + 1 - A_array - 0.5
    sup_array = np.array(range(N)) + 1 + A_array + 0.5

    for m in range(N):
        
        B_list.append(((inf_array <= m+1) & (m+1<=sup_array)).sum())

    A_array = np.array(B_list).copy()
    
print(' '.join(map(str, A_array)))

Submission status: Time Limit Exceeded

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

for j in range(k):
    s = [0] * (n + 1)
    for i in range(n):
        if i - a[i] >= 0:
            s[i - a[i]] += 1
        else:
            s[0] += 1
        if i + a[i] + 1 < n + 1:
            s[i + a[i] + 1] -= 1
        else:
            s[n] -= 1
            
    s_ = [0] * (n + 1)
    s_[0] = s[0]
    for i in range(n):
        s_[i + 1] = s_[i] + s[i + 1]
        
    a = s_
    
print(*s_[:n])

Submission status: Time Limit Exceeded

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

ans = A
for k in range(K):
    temp = [0 for _ in range(N)]
    for i in range(N):
        a = ans[i]
        temp[max(i-a, 0)] += 1
        if i + a + 1 < N:
            temp[i+a+1] -= 1

    ans[0] = temp[0]
    for j in range(1, N):
        ans[j] = ans[j-1] + temp[j]

for i in range(N):
    print(ans[i], end=" ")

Submission status: Time Limit Exceeded

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


for i in range(1, k+1):
    tmp_list = [0 for i in range(n)]
    for j in range(n):
        #tmp_list[j] += 1
        a = a_list[j]
        start_k = 0
        end_k = n
        if j - a < 0:
            start_k = 0
            #for k in range(j):
            #    tmp_list[k] += 1
        else:
            start_k = j - a
            #for k in range(j-a, j):
            #    tmp_list[k] += 1
        if j + a > n - 1:
            end_k = n
            #for k in range(j + 1, n):
            #    tmp_list[k] += 1
        else:
            end_k = j + a + 1
            #for k in range(j + 1, j + a + 1):
            #    tmp_list[k] += 1
        for k in range(start_k, end_k):
            tmp_list[k] += 1
    a_list = tmp_list
    #print(tmp_list)
print(' '.join(map(str, a_list)))

Submission status: Time Limit Exceeded

Solution code:
#C
N,K = map(int, input().split())
lights = list(map(int, input().split()))
bright = [0 for i in range(N)]

#Kがある程度大きい場合、すべての項がNになるので、以下の動作を省く
count = 0
for light in lights:
    if light > 0:
        count+=1
if (count*(N-min(lights))<=K):
    lights = [N for y in range(N)]
    
else:
    for kaisuu in range(K):
    #すべての電球の明るさがNになったら終わる
        if sum(lights) == N**2:
            break
        for i in range(N):
            count = lights[i]
            for j in range(i-count,i+count+1):
                if 0<=j<=N-1:
                    bright[j]+=1
        lights = bright
        bright = [0 for z in range(N)]
        #print(kaisuu,lights)
        #print(kaisuu,bright)
for ans in lights:
    print(ans, end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

#Sn = np.array([[0 for i in range(N)] for i in range(N)])
#for i in range(N):
#    Sn[i][max(0,i - An[i]): min(i + An[i] + 1, N)] = 1
#print(Sn)
buf = np.array(range(N))

for i in range(K):
    Hn = buf + An#np.array([ i + An[i] for i in range(N)])
    Ln = buf - An#np.array([ i - An[i] for i in range(N)])
    #print(Hn)
    #print(Ln)
    An = [sum((Ln<=i)&(i<=Hn)) for i in range(N)]
    

print(*An)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

for p in range(k):
  tmp=copy.deepcopy(a)
  for i in range(len(a)):
    x=0
    for j in range(len(tmp)):
      if abs(i-j) < tmp[j] + 0.5:
        x=x+1
    a[i]=x
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
n,k = map(int,input().split())
l = [int(x) for x in input().split()]
for p in range(k):
  l2 = [0 for _ in range(n)]
  for i in range(n):
    x = i + 1
    d = l[i]
    r1 = x - d - 0.5
    r2 = x + d + 0.5
    for j in range(1,n+1):
      if(r1 < j and j < r2):
        l2[j-1] += 1
  for o in range(n):
    l[o] = l2[o]
l2=[str(a) for a in l2]
l2=" ".join(l2)
print(l2)

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

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
        for j in range(n):
            for k in range(max(0,j-a[j]),min(n-1,j+a[j])+1):
                b[k] += 1
        a = b
    c = [str(a) for a in b]
print(' '.join(c))

Submission status: Time Limit Exceeded

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

dp = [[0] * 2 for i in range(n)]

ans = l[:]
for j in range(n):
    dp[j][0] = (j+1 - ans[j] - 0.5)
    dp[j][1] = (j+1 + ans[j] + 0.5)

for i in range(k):
    ans = [0] * n
    for x in range(n):
        for y in range(n):
            if dp[y][0] <= x+1 <= dp[y][1]:
                ans[x] += 1
    for j in range(n):
        dp[j][0] = (j+1 - ans[j] - 0.5)
        dp[j][1] = (j+1 + ans[j] + 0.5)

print(*ans)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int, input().split())
A=list(map(int, input().split()))
B=[0]*N
C=A

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