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 copy

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):
        c=max(i-A[i],0)
        while c<=min(i+A[i],N-1):
            L[c]+=1
            c+=1
    A = copy.copy(L)
 
print(' '.join(map(str,A)))

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):
    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):
        nextA[k] += 1
  As = nextA

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

Submission status: Time Limit Exceeded

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

temp=A
max_pow=0

for i in range(K):
  max_pow=max(A)
  temp=[0]*N
  for j in range(N):
    for k in range(-max_pow,max_pow+1):
      if(j+k>=0 and j+k<=len(A)-1):
        if(A[j+k]>=abs(k)):
          temp[j]=temp[j]+1
  A=temp

print(*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):
        S = j - A[j]
        G = j + A[j] 
        if S < 0:
            S = 0
        if G >= len(A):
            G = len(A) - 1
        
        B[S:G+1] = [x + y for (x, y) in zip(B[S:G+1], [1] * (G-S+1))]
        
    if A == B: 
        break
    else:
        A = B
        
print(*B)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy
import math
def main():
    N, K = map(int, input().split())
    a = [float(i) for i in input().split()]
    A = [0] * (N + 1)
    if K >= 41:
        for i in range(1, N+1):
            if i > 1:
                print(' ', end='')
            print(N, end='')
        print()
        sys.exit()
    for i in range(1, N+1):
        A[i] = a[i - 1]
    for _ in range(K):
        count = [0] * (N + 1)
        for i in range(1, N+1):
            if A[i] >= N:
                left_d = 1
                right_d = N
            else:
                left_d = math.ceil(i - A[i] - 0.5)
                right_d =  math.floor(i + A[i] + 0.5)
                if left_d < 1:
                    left_d = 1
                if right_d > N:
                    right_d = N
            for j in range(left_d, right_d+1):
                count[j] += 1
        A = copy.copy(count)
        flag = True
        for i in range(1, N+1):
            if A[i] != N:
                flag = False
                break
        if flag:
            break
    for i in range(1, N+1):
        if i > 1:
            print(' ', end='')
        print(A[i], end='')
    print()


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
*A, = map(int, input().split())
for _ in range(min(K, 50)):
    counter = [0] * (N+2)
    for i, a in enumerate(A, 1):
        counter[max(0, i - a)] += 1
        counter[min(N + 1, i + a + 1)] += -1
    for i in range(1, len(counter) - 1):
        counter[i] += counter[i-1]
    A = counter[1:N+1]
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, k = rm()
a = rl()
k = min(k, 50)
if n <= k:
    for _ in range(n):
        print(n, end=' ')
    exit()
for _ in range(k):
    li = [0] * n
    for i in range(n):
      s = max(i - a[i], 0)
      e = min(i + a[i], n-1)
      for m in range(s, e+1):
        li[m] += 1
    if a == li:
      break
    a = li
for v in a:
    print(v, end=' ')

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,k = map(int,input().split())
    A = list(map(int,input().split()))
    k = min(50,k)

    dp = [[0]*n for _ in range(k+1)]
    for i in range(n):
        dp[0][i] = A[i]

    flag = False
    for i in range(1,k+1):
        pos = [0]*n
        neg = [0]*n

        for j in range(n):
            pwr = dp[i-1][j]
            pos[max(0,j-pwr)]+=1
            neg[min(n-1,j+pwr)]+=1

        ac_pos = 0
        ac_neg = 0
        for j in range(n):
            ac_pos += pos[j]
            ac_neg += neg[j]
            pos[j] = ac_pos
            neg[j] = ac_neg

        if pos[0]==n and neg[n-2]==0:
            flag = True
            break

        dp[i][0] = pos[0]
        for j in range(1,n):
            dp[i][j] = pos[j] - neg[j-1]

    
    if flag:
        for j in range(n-1):
            print(n, end=" ")  
        print(n)

    else:
        for j in range(n-1):
            print(dp[i][j], end=" ")
        print(dp[i][n-1])
main()

Submission status: Time Limit Exceeded

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

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

print(" ".join([str(item) for item in work]))

Submission status: Time Limit Exceeded

Solution code:
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
if k >= len(ls):
    for q in range(len(ls)):
        print(len(ls),end=" ")
    sys.exit()
for _ in range(k):
    new = [0]*n
    for i in range(n):
        p = 0
        for l in range(1,max(n-i,i+1)):
            if i+l >= 0 and i+l <n:
                if ls[i+l] >= l:
                    p += 1
            if i-l >= 0 and i-l <n:
                if ls[i-l] >= l:
                    p += 1
        new[i] = p+1
    ls = new
print(*ls)

Submission status: Time Limit Exceeded

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

current_arr = A
for k in range(K):
    next_arr = [0]*N
    for i, ai in enumerate(current_arr):
        for num in range(-ai, ai+1):
            ii = i + num
            if ii < 0 or N <= ii:
                continue
            next_arr[ii] += 1
    current_arr = next_arr
print(*next_arr)

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]

    if ans.count(N) == N:
        break

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

Submission status: Time Limit Exceeded

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

A.append(0)

for j in range(K):
    B = [0] * (N+1)
    for i in range(N):
        B[max(i - A[i],0)] += 1
        B[min(i + A[i] + 1,N)] -= 1
    A = [0] * (N+1)
    a = 0
    for i in range(N):
        a += B[i]
        A[i] = a

print(*A[:-1])

Submission status: Time Limit Exceeded

Solution code:
def get_lump(target_list, num):
    result_list = [0] * num
    flg = False
    for target in target_list:
        if target < num:
            flg = True
            break

    if flg:
        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 < max_range:
                    result_list[result_num] += 1
        return result_list
    else:
        return target_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:
def solve():
  N, K = map(int,input().split())
  AA = list(map(int,input().split()))
  for k in range(K):
    AA2 = [0]*N
    base = 2**k-1
    for i in range(N):
      if i<k-1:
        base_0 = 2**(k-1)+i
      elif i>(N-k):
        base_0 = 2**(k-1)+(N-i)-1
      else:
        base_0 = base
      if AA[i]!=0:
        effect = AA[i]
        effect_i = i - base_0 - effect
        effect_i2 = i - base_0
        effect_f = i + base_0 + 1
        effect_f2 = i + base_0 + effect+1
        if effect_i<0:
          effect_i = 0
        if effect_f2 >=N:
          effect_f2 = N
        for j in range(effect_i,effect_i2):
          AA2[j] +=1
        for j in range(effect_f,effect_f2):
          AA2[j] +=1
    AA = AA2.copy()

  k = K
  base = 2**k-1
  for i in range(N):
    if i<k-1:
      base_0 = 2**(k-1)+i
    elif i>(N-k):
      base_0 = 2**(k-1)+(N-i)-1
    else:
      base_0 = base
    AA[i] += base_0
    if AA[i]>N:
      AA[i]=N

  print(' '.join([str(A) for A in AA]))
solve()

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())))
# O(log N)以下で各座標が幾つの電球の範囲に含まれるかを判定したい。

for _ in range(k):
    b = np.zeros(n,dtype='int64')
    for i,c in enumerate(a):
        l = max(0,i-c)
        r = min(n-1,i+c)
        tmp = (b[l:r+1]+1)
        if r < n-1:
            b = np.hstack((np.hstack((b[:l],tmp)),b[r+1:]))
        else:
            b = np.hstack((b[:l],tmp))
    a = b

print(*a)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(k):
        tmp = [0] * n
        for i in range(n):
            for j in range((i+1) - a[i], (i+1) + a[i] + 1):
                if 1 <= j <= n:
                    tmp[j-1] += 1
                    if len(set(tmp)) == 1 and n in set(tmp):
                        print(*tmp)
                        return
        a = tmp.copy()
    print(*a)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
# 初期入力
import sys
input = sys.stdin.readline
N,K = (int(i) for i in input().split())
A = list(map(int, input().split()))
#B =np.zeros(N)
A =np.array(A,dtype=np.int64)
#
l =0
r =N
for j in range(K):
    B =np.zeros(N,dtype=np.int64)
    for i in range(N):
        index =A[i]
        if i-index <0:
            l=0
        else:
            l =i -index
        if i +index >N:
            r =N 
        else:
            r =i +index +1
        B[l:r] +=1 
        if np.all(B >=N):
            break
    A =B
    
print(*B)

Submission status: Time Limit Exceeded

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

M=[N]*N

for i in range(K):
    L=[0]*(N+1)
    for j in range(N):
        L[max(0,j-A[j])]+=1
        L[min(N,j+A[j]+1)]-=1
        
    S=0
    for j in range(N):
        S+=L[j]
        A[j]=S

    #if A==M:
    #    break

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

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

        def __iter__(self):
            psum = 0
            for i in range(self.size):
                csum = self.sum(i+1)
                yield csum - psum
                psum = csum
            raise StopIteration()

        def __str__(self):  # O(nlogn)
            return str(list(self))

        def sum(self, i):
            # [0, i) の要素の総和を返す
            if not (0 <= i <= self.size): raise ValueError("error!")
            s = 0
            while i>0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            if not (0 <= i < self.size): raise ValueError("error!")
            i += 1
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, x):
            """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
            sum_ = 0
            pos = 0
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k <= self.size and sum_ + self.tree[k] < x:
                    sum_ += self.tree[k]
                    pos += 1 << i
            return pos + 1, sum_

        def __getitem__(self, key):
            if not (0 <= key < self.size): raise IndexError("error!")
            return self.sum(key+1) - self.sum(key)

        def __setitem__(self, key, value):
            # 足し算と引き算にはaddを使うべき
            if not (0 <= key < self.size): raise IndexError("error!")
            self.add(key, value - self[key])

    class BitImos:
        """
        ・範囲すべての要素に加算
        ・ひとつの値を取得
        の2種類のクエリをO(logn)で処理
        bit = BitImos(len(li))
        """
        def __init__(self, n):
            self.bit = Bit(n+1)

        def add(self, s, t, x):
            # [s, t)にxを加算
            self.bit.add(s, x)
            self.bit.add(t, -x)

        def get(self, i):
            return self[i]

        def __getitem__(self, key):
            # 位置iの値を取得
            return self.bit.sum(key+1)

    for i in range(k):
        bit = BitImos(n)
        for i in range(n):
            bit.add(max(0, i-a[i]), min(n, i+a[i]+1), 1)
        for i in range(n):
            a[i] = min(n, bit.get(i))
        if all((a[i]==n for i in range(n))):
            break

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

        if (pp == 0):
            d[int(j - 1)] += 1
            # print(d)
            continue
        if (pp == n):
            d += 1
            if (k - i > (n//2)):
                ans = [str(i) for i in check]
                # print(ans)
                print(' '.join(ans))
                exit()
            # print(d)
            continue

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

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

    bb = d

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


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

#s = ','.join(l)

Submission status: Time Limit Exceeded

Solution code:
import copy

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
    A = copy.copy(L)
 
print(' '.join(map(str,A)))

Submission status: Time Limit Exceeded

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

if K>=N:
    A=[N]*N
    print(" ".join(str(x) for x in A))
    exit()

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()))
g=list(range(n))
f=0
m=[n]*n
while f<k:
    t=n-len(g)
    b=[t]*n
    for x in g:
        for y in range(x-a[x],x+a[x]+1):
            if 0<=y<=n-1:
                b[y]+=1
    for x in g:
        if x + b[x] >= n - 1 and x - b[x] <= 0:
            g.remove(x)
    a=b
    f+=1
    if a==m:
        break
print(*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)
    if temp == kakou(temp):
        break

print(*temp)

Submission status: Time Limit Exceeded

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

for k in range(K):
  light = [0] * N
  for i in range(N):
    start = max(0,i-A[i])
    end = min(N-1, i+A[i])
    for j in range(start, end+1):
      light[j] += 1
  if light[0] == N and light[N-1] == N:
    break
    
  A = light

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

Submission status: Time Limit Exceeded

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

for k in range(K):
    # ans = copy.copy(A)
    ans=[0]*N
    for n in range(N):
        if A[n]==0:
            ans[n]+=1
        else:
            for j in range(n-A[n],n+A[n]+1):
                if j>=0 and j<N:
                    ans[j]+=1
        # print(A)
    # for o in range(N):
    #     A[o]=ans[o]
    A = copy.copy(ans)
print(*ans)

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())))
new_A = A
len_A=len(A)
count_list = np.zeros(len_A, dtype = int)
K_list=range(K)
A_list=range(len_A)
check_A = np.array([N]*N)
for i in K_list:
    for j in A_list:
        if(new_A[j]!=0):
            low_posi=j-new_A[j]
            if(low_posi<0):
                low_posi=0
            high_posi = j+new_A[j]
            if(high_posi>len_A):
                high_posi=len_A
            count_list[low_posi:high_posi+1] += 1
        else:
            count_list[j]+=1
    new_A=count_list
    count_list = np.zeros(len_A,dtype=int)
    if(np.allclose(new_A,check_A)):
        for s in new_A:
            print(str(s)+" ", end ="")
        exit()

for s in new_A:
  print(str(s)+" ", end ="")
print("")

Submission status: Time Limit Exceeded

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

import sys
import copy

def input():
    return sys.stdin.readline()


def resolve():
    n, k = map(int, input().split())
    a_list = list(map(int, input().split()))


    one_list = [0] * n

    for num in range(k):
        lamped_list = [0] * n
        # 照らされたランプ
        for i, strength in enumerate(a_list):
            l_range_minus = i - strength
            l_range_plus = i + strength
            if l_range_minus < 0:
                l_range_minus = 0
            if l_range_plus >= n:
                l_range_plus = n - 1

            if strength != 0:
                one_list[i] = 1

            for j in range(l_range_minus, l_range_plus+1):
                if i==j:
                    continue
                lamped_list[j] += 1
                one_list[j] = 1

            #print(lamped_list)

        # ここから最終的な光の強さを算出
        index = 0
        for i, j in zip(lamped_list, one_list):
            a_list[index] = i + j
            index += 1


    print(*a_list)









if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import copy
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
#if max(A)==0:
#  ans1=[0]*n
#  print(' '.join(map(str, ans1)))
#  exit()
if k>=n-1:
  ans2=[n]*n
  print(' '.join(map(str, ans2)))
  exit()

for c in range(k):
  B=[0]*len(A)
  for i in range(1,len(A)+1):#1~N
    for j in range(i-A[i-1],i+A[i-1]+1):
      if j>0 and j<=len(A):
        B[j-1]+=1#0~N-1
  A=copy.deepcopy(B)
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()))
maxed={}
for m in range(0,k):
    temp=[0]*n
    if len(maxed)==n:
        print(' '.join(map(str,a)))

    for i in range(0,n):
        d=a[i]
        if d==n:
            temp[i]=n
            maxed[i]=1
        elif d !=0 :
            for x in range(i-d, i+d+1):
                if x >= 0 and x < n :
                    temp[x]+=1
        else:
            temp[i]+=1
    a=copy.copy(temp)

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

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
a=input().split()
A=[int(b) for b in a]
def pluss(n):
    return n+1
for k in range(K):
    a = [1 for _ in range(N)]
    for n in range(N):
        number=A[n]
        plus=n+number
        minus=n-number
        if minus<0:
            a[:n]=map(pluss,a[:n])
        else:
            a[minus:n]=map(pluss,a[minus:n])
        if plus>N:
            a[n+1:]=map(pluss,a[n+1:])
        else:
            a[n+1:plus+1]=map(pluss,a[n+1:plus+1])
    A=a
    if sum(A)==N**2:
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
N,K=input().split()
N=int(N)
K=int(K)
A=list(map(int,input().split()))
if K==1:
    B=[0]*N
    j=0
    for j in range(0,N):
        if A[j]>0:
            a=j-A[j]
            b=j+A[j]
            if a<0:
                a=0
            if b>=N:
                b=N-1
            k=a
            C=[1]*(b-a+1)
            B[a:b+1]=[x+y for (x, y) in zip(B[a:b+1],C)]
        if A[j]==0:
            B[j]+=1
        j+=1
    A=B
i=0
if K>=2:
    for i in range(0,K):
        B=[0]*N
        j=0
        for j in range(0,N):
            if A[j]>0:
                a=j-A[j]
                b=j+A[j]
                if a<0:
                    a=0
                if b>=N:
                    b=N-1
                k=a
                C=[1]*(b-a+1)
                B[a:b+1]=[x+y for (x, y) in zip(B[a:b+1],C)]
            if A[j]==0:
                B[j]+=1
            j+=1
        A=B
        i+=1
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys

rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, k = rm()
a = rl()
if n <= k:
    for _ in range(n):
        print(n, end=' ')
    exit()
for _ in range(k):
    li = [0] * n
    for i in range(n):
      s = max(i - a[i], 0)
      e = min(i + a[i], n-1)
      for m in range(s, e+1):
        li[m] += 1
    if a == li:
      break
    a = li
for v in a:
    print(v, end=' ')

Submission status: Time Limit Exceeded

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

for k in range(K):
    newLight = [0] * N
    for i in range(N):
        for j in range(N):
            if d[k][j] - abs(j - i) >= 0:
                newLight[i] += 1
    d.append(newLight)

dk = d[K]
res = str(dk[0])
for i in range(1, N):
    res += " " + str(dk[i])
print(res)

Submission status: Time Limit Exceeded

Solution code:
import copy
n,k,*A = map(int,open(0).read().split())

A_1 = copy.deepcopy(A)
A_2 = copy.deepcopy(A)
for _ in range(k):
    A_1_1 = copy.deepcopy(A)
    if _ == 0:A = [0] * n
    for i,d in enumerate(A_1):
        if d >= max(n-i,i):continue
        for j in range(i-d,i+d+1):
            if 0<=j<n:
                if _ != 0 and i-A_2[i]<=j<=i+A_2[i]:continue
                A[j] += 1
    A_2 = copy.deepcopy(A_1); A_1 = copy.deepcopy(A)
    up = True
    for i,c in enumerate(A):
        if c < max(n-i,i+1):
            up = False          
    if up:
        break
print(*A)

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,20)):
    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)

print(*A)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
li = [int(i) for i in input().split()]
light = []
count = 0

for m in range(0, k):
  for l in range(0, len(li)):
    for s in range(0, len(li)):
      if li[s] >= abs(l - s):
        count += 1
    light.append(count)
    count = 0
  li = light
  light = [] 

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

Submission status: Time Limit Exceeded

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

base_list = [0] * N

for l in range(K):

    list_copy = A.copy()
    A = base_list.copy()

    for i, j in enumerate(list_copy, 1):
        if i - j >= 1:
            low = i - j
        else:
            low = 1
        if i + j <= N:
            high = i + j
        else:
            high = N
        for k in range(low - 1, high):
                A[k] += 1

ans = map(str, A)
ans = " ".join(ans)

print(ans)

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):
        tmp = ans[j] + 0.5
        dp[j][0] = (j+1 - tmp)
        dp[j][1] = (j+1 + tmp)

    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:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(k):
        tmp = [0] * n
        for i in range(n):
            for j in range((i+1) - a[i], (i+1) + a[i] + 1):
                if 1 <= j <= n:
                    tmp[j-1] += 1
            if len(set(tmp)) == 1 and n in set(tmp):
                print(*tmp)
                return
        a = tmp.copy()
    print(*a)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def func3(lst):
    out = []
    for i in range(n):
        cnt = 0
        for j in range(n):
            if lst[j] - abs(i-j) >=0:
                cnt +=1
        out.append(cnt)
    return out

for i in range(k):
    data = func3(data)
    if min(data) == n:
        print(i)
        break

out = str(data[0])
for d in data[1:]:
    out += ' ' + str(d)
print(out)

Submission status: Time Limit Exceeded

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

for num in range(k):
    light = []
    ans = [0] * n
    for i,ramp in enumerate(li,1):
        a = max(i - ramp,1)
        b = min(i + ramp,n)
        light.append([a,b])

    for j, k in light:
        for l in range(j,k+1):
            ans[l-1] += 1
    li = ans.copy()

print(*ans,sep=" ")

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(x) for x in input().split()]
lamp_list = list(map(int, input().split()))
 
for x in range(K):
    light = [0 for x in range(N)]
    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
        # print(f"lower:{lower} high:{higher}")
        for j in range(lower, higher):
            light[j] += 1
        # print(f"i:{i} pow{lamp_power}")
        # print(light)
    lamp_list = light
 
print(" ".join(map(str, list(lamp_list))))

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import Counter


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

for _ in range(k):
    l = []
    b = [0]*n
    for i in range(1, n+1):
        x = math.ceil(i-a[i-1]-0.5)
        y = math.floor(i+a[i-1]+0.5)
        l += list(range(x, y+1))
    c = Counter(l)
    for num in range(n):
        b[num] = c[num+1]
    a = b
print(' '.join(map(str, b)))

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
lst = list(map(int, input().split()))
for i in range(k):
    lit = [0 for _ in range(n)]
    for _ in range(0, n):
        mx = max(0,_ - lst[_])
        mn = min(n, _ + lst[_] +1)
        lit[mx:mn] = map(lambda x:x+1, lit[mx:mn])
    lst = lit
    if set(lst) == {n}:
        break
lst = [str(_) for _ in lst]
ans = ' '.join(lst)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(K):
   B=[0]*N
   for l in range(N):
      d=A[l]
      if d==0:
         B[l]+=1
      else:
         for i in range(max(l-d,0),min(l+d+1,N),1):
            B[i]+=1
   A=B
A=[str(a) for a in A]
A=' '.join(A)
print(A)