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

def f(x):
    if x == 0:
        return ls
    elif x < 19:
        lsa = [0 for i in range(n)]
        lsb = f(x-1)
        for j in range(n):
            if lsb[j] == 0:
                lsa[j] += 1
            else:
                if lsb[j] - j - 1 < 0:
                    if j + lsb[j] - n < 0:
                        for l in range(j -lsb[j], j + lsb[j] + 1):
                            lsa[l] += 1
                    else:
                        for l in range(j - lsb[j], n ):
                            lsa[l] += 1
                else:
                    if j + lsb[j] - n < 0:
                        for l in range(j + lsb[j] + 1):
                            lsa[l] += 1
                    else:
                        for l in range(n):
                            lsa[l] += 1
        return lsa
    else:
        lsc = [x - k for i in range(n)]
        for j in range(n):
            lsc[j] += f(18)[j]
        return lsc

for m in range(n):
    print(f(k)[m], end = " ")

Submission status: Time Limit Exceeded

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

if K>100:
    ans = [str(N)]*N
    print(' '.join(ans))
    exit()

light = [0]*N
last_light = A
for j in range(K):
    for i in range(N):
        if i-last_light[i] < 0:
            start = 0
        else:
            start = i-last_light[i]
        if i+last_light[i] > N:
            last = N
        else:
            last = i+last_light[i]
        light = light[:start] + list(map(lambda x:x+1,light[start:last+1])) + light[last+1:]
    last_light = copy.copy(light)
    light = [0]*N

for i in range(N):
    last_light[i] = str(last_light[i])
print(' '.join(last_light))

Submission status: Time Limit Exceeded

Solution code:
def right(a,n):
    sw = [0]*(n+1)
    for x,y in enumerate(a):
        x_min = max(0,x-y)
        x_max = min(n,x+y+1)
        sw[x_min] += 1
        sw[x_max] -= 1
    s = 0
    for i in range(n):
        s += sw[i]
        a[i] = s
    return a

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(min(k,50)):
    a = right(a,n)
a = [str(n) for n in a]
print(" ".join(a))

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] * (N+1)
  for i in range(N):
    l = max(0, i-A[i])
    r = min(i+A[i]+1, N)
    B[l] += 1
    B[r] -= 1

  for i in range(N):
    B[i+1] += B[i]

  if B[:-1] == A: break
  A = B

for i in range(N):
  print(A[i])

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

if K > 50:
    print(" ".join([str(N) for i in range(N)]))
    sys.exit()

for i in range(K):
    A_new = [0 for i in range(N)]
    imos_table = [0 for i in range(N)]

    for j in range(N): # ここで一度状態の差分についてをimos_tableに保存
        left = max(0, j - A[j])
        right = j + A[j] + 1
        imos_table[left] += 1
        if right >= N:
            pass
        else:
            imos_table[right] -= 1
    
    # tmp を使って前から順に状態を計算していく
    tmp = 0
    for j in range(N):
        tmp += imos_table[j]
        A_new[j] += tmp

    A = copy.deepcopy(A_new)

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 _ in range(K):
    forR = [0]*N
    forL = [0]*N
    for i in range(N):
        d = A[i]
        if d > 0:
            if i+1 <= N-1:
                forR[i+1] += 1
            if i+d+1 <= N-1:
                forR[i+d+1] -= 1
    for i in range(N-1,-1,-1):
        d = A[i]
        if d > 0:
            if i-1 >= 0:
                forL[i-1] += 1
            if i-d-1 >= 0:
                forL[i-d-1] -= 1

    ansR = [0]*N
    ansL = [0]*N
    for i in range(1,N):
        ansR[i] = ansR[i-1] + forR[i]
    for i in range(N-2,-1,-1):
        ansL[i] = ansL[i+1] + forL[i]

    B = [x+y+1 for x,y in zip(ansR,ansL)]
    if B == A:
        break
    else:
        A = B
print(*A)

Submission status: Time Limit Exceeded

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

for _ in range(K):
    forR = [0]*N
    forL = [0]*N
    for i in range(N):
        d = A[i]
        if d > 0:
            if i+1 <= N-1:
                forR[i+1] += 1
            if i+d+1 <= N-1:
                forR[i+d+1] -= 1
    for i in range(N-1,-1,-1):
        d = A[i]
        if d > 0:
            if i-1 >= 0:
                forL[i-1] += 1
            if i-d-1 >= 0:
                forL[i-d-1] -= 1

    ansR = [0]*N
    ansL = [0]*N
    for i in range(1,N):
        ansR[i] = ansR[i-1] + forR[i]
    for i in range(N-2,-1,-1):
        ansL[i] = ansL[i+1] + forL[i]

    A = [x+y+1 for x,y in zip(ansR,ansL)]
print(*A)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

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

    N = 2* 10 ** 5
    K = N
    A = [0]*N
    arr = [0]*(N+1)

    for _ in range(K):
        arr = [0]*(N+1)
        for i, a in enumerate(A):
            left = max(0, i-a)
            right = min(N, i+a+1)
            arr[left] += 1
            arr[right] -= 1
        
        A = list(accumulate(arr[:-1]))
        if all(a == N for a in A):
           break

    print(*A[:-1], sep=" ")



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
n, k, *A = map(int, open(0).read().split())
for _ in range(min(k, 50)):
    B = [0] * (n+1)
    for i in range(n):
        B[max(0, i-A[i])] += 1
        B[min(n, i+A[i]+1)] -= 1
    *A, = accumulate(B)
print(*A[:n])

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
n, k, *A = map(int, open(0).read().split())
for _ in range(min(k, 50)):
    B = [0] * (n+1)
    for i in range(n):
        B[max(0, i-A[i])] += 1
        B[min(n, i+A[i]+1)] -= 1
    A = list(accumulate(B))[:n]
print(*A)

Submission status: Time Limit Exceeded

Solution code:
def OK():
    N,K=map(int,input().split())
    A = list(map(int,input().split()))
 
    l_chk=[0 for _ in range(N)]
    cnt = 0
    for i in range(K):
 
        for j in range(N):
            cnt = 0
            for k in range(N):
                if A[j] == N:
                    break
                if j == k:
                    cnt = cnt + 1
                elif abs(k-j) <= A[k]:
                    cnt = cnt + 1
            l_chk[j] = cnt
        for j in range(N):
            A[j] = l_chk[j]
 
 
    print(*A)
 
OK()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit

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

A_list = [0]+list(map(int, input().split()))
A_np=np.array(A_list)
#print(A_np)

@njit
def update(A_np):
  new_A_np=np.array([0]*(N+1))
  for i in range(1,N+1):
    tmp_np=np.array([0]*(N+1))
    #print(A_np)
    mi=i-A_np[i]
    ma=i+A_np[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #print(mi,ma)
    tmp_np[mi:ma+1]=1
    #print(tmp_np)
    new_A_np+=tmp_np
  #print(new_A_np)
  A_np=new_A_np
  return(A_np)

for j in range(K):
  A_np=update(A_np)
  if sum(A_np[1:N+1])==N*N:
    break
    
for i in range(1,N+1):
  print(A_np[i],end=" ")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit

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

A_list = [0]+list(map(int, input().split()))
A_np=np.array(A_list)
#print(A_np)


def update(A_np):
  new_A_np=np.array([0]*(N+1))
  for i in range(1,N+1):
    tmp_np=np.array([0]*(N+1))
    #print(A_np)
    mi=i-A_np[i]
    ma=i+A_np[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #print(mi,ma)
    tmp_np[mi:ma+1]=1
    #print(tmp_np)
    new_A_np+=tmp_np
  #print(new_A_np)
  A_np=new_A_np
  return(A_np)

for j in range(K):
  A_np=update(A_np)
  if sum(A_np[1:N+1])==N*N:
    break
    
for i in range(1,N+1):
  print(A_np[i],end=" ")

Submission status: Time Limit Exceeded

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

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


for _ in range(K):

    NextA = [0]*N

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

    if A == [N]*N:
        print(' '.join(map(str, A)))
        exit()

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

Submission status: Time Limit Exceeded

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

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    for k in range(K):
        A_temp=[0]*(N+1)
        for i in range(N):
            A_temp[max(0,i-A[i])]+=1
            if i+A[i]+1<=N-1:
                A_temp[i+A[i]+1]-=1
            
        A[0]=A_temp[0]
        for j in range(1,N):
            A_temp[j]+=A_temp[j-1]
            A[j]=A_temp[j]
        for ai in A:
            if ai != N:
                break
        else:
            break
                
    print(' '.join([str(a) for a in A]))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    for k in range(K):
        A_temp=[0]*(N+1)
        for i in range(N):
            A_temp[max(0,i-A[i])]+=1
            if i+A[i]+1<=N-1:
                A_temp[i+A[i]+1]-=1
            
        A[0]=A_temp[0]
        for j in range(1,N):
            A_temp[j]+=A_temp[j-1]
            A[j]=A_temp[j]
        for ai in A:
            if ai != N:
                break
        else:
            break
                
    print(*A)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

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

    l_chk=[0] * N
    cnt = 0
    for i in range(K):

        for j in range(N):
            cnt = 0
            for k in range(N):
                if A[j] == N:
                    break
                if j == k:
                    cnt = cnt + 1
                elif abs(k-j) <= A[k]:
                    cnt = cnt + 1
            l_chk[j] = cnt
        for j in range(N):
            A[j] = l_chk[j]


    print(*A)

OK()

Submission status: Time Limit Exceeded

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

def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    for k in range(K):
        A_temp=[0]*N
        for i in range(N):
            A_temp[max(0,i-A[i])]+=1
            if N-1>=i+A[i]+1:
                A_temp[i+A[i]+1]-=1
            
        A[0]=A_temp[0]
        for j in range(1,N):
            A_temp[j]+=A_temp[j-1]
            A[j]=A_temp[j]
        for ai in A:
            if ai != N:
                break
        else:
            break
                
    print(*A)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from numba import njit

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

A_list = np.array([0]+list(map(int, input().split())))

@njit
def update(A_list):

  for j in range(K):
    new_A=np.zeros(N+2,dtype=np.int64)
    for i in range(1,N+1):
      #print(new_A)
      mi=i-A_list[i]
      ma=i+A_list[i]
      if mi<0:
        mi=0
      if ma>N:
        ma=N
      #new_A[mi:ma+1]+=1
      new_A[mi]+=1
      new_A[ma+1]-=1

    A_list=np.cumsum(new_A)
    #if sum(A_list[1:N+1])==N*N:
    #  return(A_list)    
    #  break
      
  return(A_list)

A_list=update(A_list)
for i in range(1,N+1):
  print(A_list[i],end=" ")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
  b = [0] * (n + 1)
  for i in range(n):
    left_edge = max(0, i-a[i])
    right_edge = min(i + a[i] + 1, n)
    b[left_edge] += 1
    b[right_edge] -= 1
  for i in range(1, n+1):
    b[i] = b[i] + b[i-1]
  b.pop(n)
  if a == b:
    break
  a = b.copy()
print(' '.join(str(b[i]) for i in range(n)))

Submission status: Time Limit Exceeded

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

A_list = np.array([0]+list(map(int, input().split())))
#print(A_np)


for j in range(min(K,46)):
  new_A=np.zeros(N+2,dtype=np.int64)
  for i in range(1,N+1):
    #print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma+1]-=1

  A_list=np.cumsum(new_A)
  #if A_list[1:N+1])==N*N:
  #  break
    
for i in range(1,N+1):
  print(A_list[i],end=" ")

Submission status: Time Limit Exceeded

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

A_list = np.array([0]+list(map(int, input().split())))
#print(A_np)


for j in range(K):
  new_A=np.zeros(N+2,dtype=np.int64)
  for i in range(1,N+1):
    #print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma+1]-=1

  A_list=np.cumsum(new_A)
  if sum(A_list[1:N+1])==N*N:
    break
    
for i in range(1,N+1):
  print(A_list[i],end=" ")

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(min(K, 41)):
  aa = [0]*(N+1)
  for j in range(N):
    aa[max(0,j-A[j])] += 1
    aa[min(N,j+A[j]+1)] -= 1
    l = max(0,j-A[j])
  A[0] = aa[0]
  for j in range(1, N):
    A[j] = A[j-1]+aa[j]
for aa in A:
  print(str(aa) + " ", end="")

Submission status: Time Limit Exceeded

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

A_list = np.array([0]+list(map(int, input().split())))
#print(A_np)


for j in range(K):
  new_A=np.array([0]*(N+2))
  for i in range(1,N+1):
    #print(new_A)
    mi=i-A_list[i]
    ma=i+A_list[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #new_A[mi:ma+1]+=1
    new_A[mi]+=1
    new_A[ma+1]-=1

  A_list=np.cumsum(new_A)
  if sum(A_list[1:N+1])==N*N:
    break
    
for i in range(1,N+1):
  print(A_list[i],end=" ")

Submission status: Time Limit Exceeded

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

for i in range(50):
    if cnt == K:
        break
    L = [0] * N
    for j in range(N):
        for k in range(-A[j], A[j] + 1):
            if j + k >= 0 and j + k <= N - 1:
                L[j + k] += 1
    A = L
    cnt += 1

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

Submission status: Time Limit Exceeded

Solution code:
n,k,*a=map(int,open(0).read().split())
import numpy as np
a=np.array(a)
x=np.array([n]*n)
for _ in range(k):
    b=np.zeros(n,int)
    for i in range(n):
        b[max(0,i-a[i]):min(n-1,i+a[i])+1]+=1
    a=b.copy()
    if np.all(a==x):
        break
print(*a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
  b = [0] * (n + 1)
  for i in range(n):
    left_edge = max(0, i-a[i])
    right_edge = min(i + a[i] + 1, n)
    b[left_edge] += 1
    b[right_edge] -= 1
  for i in range(1, n+1):
    b[i] = b[i] + b[i-1]
  if a == b:
    break
  a = b.copy()
print(' '.join(str(b[i]) for i in range(n)))

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


K = min(K, 100)
for j in range(K):
    B = np.zeros_like(A)
    for i in range(N):
        fro=max(0,i-A[i])
        to=min(i+A[i],N-1)
        B[fro] += 1
        if to+1 < N:
            B[to+1] -= 1
        #print(fro)
        #print(to)
        #print(Alight)
    #print(A)
    A=np.cumsum(B)
    #print("------")
    #print(A)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,k = map(int,input().split())
l = [int(a) for a in input().split()]
for _ in range(min(k,41)):
    a = [0] * (N+1)
    for i,x in enumerate(l):
        a[max(0,i-x)] += 1
        a[min(i+x+1,N)] -= 1
    a_l = np.cumsum(np.array(a))[:-1].tolist()
    l = a_l
print(' '.join(map(str, a_l)))

Submission status: Time Limit Exceeded

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

l_chk=[0] * N
cnt = 0
for i in range(K):

    for j in range(N):
        cnt = 0
        for k in range(N):
            if A[j] == N:
                break
            if j == k:
                cnt = cnt + 1
            elif abs(k-j) <= A[k]:
                cnt = cnt + 1
        l_chk[j] = cnt
    for j in range(N):
        A[j] = l_chk[j]


print(*A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import numba
from numba import jit, njit, prange
# -- numba (jit compile) ------------
# @njit


@njit('i8,i8[::1],i8[::1]', cache=True)
def calc(x, zero, BB):
    for j in range(1, x + 1):
        pp = BB[j - 1]

        if (pp == 0):
            zero[int(j - 1)] += 1
            # print(d)
            continue
        if (pp == x):
            zero += 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 > x - 1):
            right = x
        #print('L&R: ', left, right)

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

    return zero


# ---- read ---------------------------------
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)
# --- main ----------------------------
for i in range(k):
    #d = [0] * n
    # print(i)
    d = np.zeros(n, dtype=np.int64)
    d = calc(n, d, bb)
    bb = d

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int,input().split())
A = list(map(int,input().split()))
imos = [0]*(n+1)
for j in range(min(k,50)):
    if j==0:
        arr = A
    else:
        arr = imos
    imos = [0]*(n+1)
    for i,a in enumerate(arr):
        imos[max(i-a, 0)] += 1
        imos[min(i+a+1, n)] -= 1
    imos = list(np.cumsum(imos))[:-1]
    if set(imos)=={n}:
        break
print(*imos)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int,input().split())
A = list(map(int,input().split()))
imos = [0]*(n+1)
for j in range(k):
    if j==0:
        arr = A
    else:
        arr = imos
    imos = [0]*(n+1)
    for i,a in enumerate(arr):
        imos[max(i-a, 0)] += 1
        imos[min(i+a+1, n)] -= 1
    imos = list(np.cumsum(imos))[:-1]
    if set(imos)=={n}:
        break
print(*imos)

Submission status: Time Limit Exceeded

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

ans1=[0]*n

for b in range(0,n):
  temp=ans[b]
    
  d=b-temp
  if d <= 0:
    d=0
  e=b+temp
  if e >= n-1:
    e=n-1
  for c in range(d,e+1):
    ans1[c]=ans1[c]+1
    
if k >=100:
  k=50
    
for a in range(0,k-1):
  ans2=ans1
  ans3=[0]*n
  for b in range(0,n):
  	temp=ans1[b]
    
  	d=b-temp
  	if d <= 0:
    	 d=0
  	e=b+temp
  	if e >= n-1:
    	 e=n-1
  	for c in range(d,e+1):
    	 ans3[c]=ans3[c]+1
  ans1=ans3
  


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

Submission status: Time Limit Exceeded

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

ans1=[0]*n

for b in range(0,n):
  temp=ans[b]
    
  d=b-temp
  if d <= 0:
    d=0
  e=b+temp
  if e >= n-1:
    e=n-1
  for c in range(d,e+1):
    ans1[c]=ans1[c]+1
    
if k >=100:
  k=100
    
for a in range(0,k-1):
  ans2=ans1
  ans3=[0]*n
  for b in range(0,n):
  	temp=ans1[b]
    
  	d=b-temp
  	if d <= 0:
    	 d=0
  	e=b+temp
  	if e >= n-1:
    	 e=n-1
  	for c in range(d,e+1):
    	 ans3[c]=ans3[c]+1
  ans1=ans3
  if ans1.count(n)==n:
    break
  


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

Submission status: Time Limit Exceeded

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

ans1=[0]*n

for b in range(0,n):
  temp=ans[b]
    
  d=b-temp
  if d <= 0:
    d=0
  e=b+temp
  if e >= n-1:
    e=n-1
  for c in range(d,e+1):
    ans1[c]=ans1[c]+1
    
if k >=100:
  k==100
    
for a in range(0,k-1):
  ans2=ans1
  ans3=[0]*n
  for b in range(0,n):
  	temp=ans1[b]
    
  	d=b-temp
  	if d <= 0:
    	 d=0
  	e=b+temp
  	if e >= n-1:
    	 e=n-1
  	for c in range(d,e+1):
    	 ans3[c]=ans3[c]+1
  ans1=ans3
  if ans1.count(n)==n:
    break
  


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

l1= input().split(' ')
n= int(l1[0])
k= int(l1[1])

start= np.array(input().split(' '))

def f(ar, n):
	new= np.array([0]*n)
	for index in range(0,n):
		d=int(start[index])
		if index-d<0:
			if index+d>len(ar)-1:
				for k in range(0, n):
					new[k]+=1
			else:
				for k in range(0, index+d+1):
					new[k]+=1
		elif index+d>len(ar)-1:
			for k in range(index-d, n):
				new[k]+=1
		else:
			for k in range(index-d, index+d+1):
				new[k]+=1
	return new
	'''
	new= ar.copy()
	for index in range(n):
		for index2 in range(n):
			if int(new[index2])>=abs(index-index2):
				ar[index]= str(int(ar[index])+1)
				print('added to', index, 'for', index2)
	return ar
	'''
'''
	new= [0]*n
	for index in range(n):
		d= int(start[index])
		try:
			for k in range(index-d, index+d+1):
				new[k]+=1
		except:
			try:
				for k in range(index-d, n):
					new[k]+=1
			except:
				try:
					for k in range(0, index+d+1):
						new[k]+=1
				except:
					for k in range(0, n):
						new[k]+=1
	return new
'''
	

for _ in range(0,k):
	start= f(start, n)
print(*start, sep=' ')

Submission status: Time Limit Exceeded

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

ans1=[0]*n

for b in range(0,n):
  temp=ans[b]
    
  d=b-temp
  if d <= 0:
    d=0
  e=b+temp
  if e >= n-1:
    e=n-1
  for c in range(d,e+1):
    ans1[c]=ans1[c]+1
    

    
for a in range(0,k-1):
  ans2=ans1
  ans3=[0]*n
  for b in range(0,n):
  	temp=ans1[b]
    
  	d=b-temp
  	if d <= 0:
    	 d=0
  	e=b+temp
  	if e >= n-1:
    	 e=n-1
  	for c in range(d,e+1):
    	 ans3[c]=ans3[c]+1
  ans1=ans3
  if ans1.count(n)==n:
    break
  


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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
  b = [0] * (n + 1)
  for i in range(n):
    left_edge = max(0, i-a[i])
    right_edge = min(i + a[i] + 1, n)
    b[left_edge] += 1
    b[right_edge] -= 1
  for i in range(1, n+1):
    b[i] = b[i] + b[i-1]
  if a[0:n] == b[0:n]:
    break
  a = b.copy()
print(' '.join(str(b[i]) for i in range(n)))

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())))
check_A = np.array([N]*N)
new_A = A
len_A=len(A)
count_list = np.zeros(len_A, dtype = int)
K_list=range(K)
A_list=range(len_A)
max_list=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(check_A,new_A)):
        for s in new_A:
          print(str(s)+" ", end ="")
        exit()
for s in new_A:
  print(str(s)+" ", end ="")

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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



for i in range(K):
    A_new = [0 for i in range(N)]
    imos_table = [0 for i in range(N)]

    for j in range(N):
        left = max(0, j - A[j])
        right = j + A[j] + 1
        imos_table[left] += 1
        if right >= N:
            pass
        else:
            imos_table[right] -= 1
    
    tmp = 0
    for j in range(N):
        tmp += imos_table[j]
        A_new[j] += tmp

    A = copy.deepcopy(A_new)

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:
    for i in range(n):
        print(n, end=" ")
    exit()

ans = [[0]*n for i in range(k+1)]
ans[0] = a

for i in range(k):
    for j in range(n):
        s = max(0,j-ans[i][j])
        g = min(n,j+ans[i][j]+1)
        for l in range(s,g):
            ans[i+1][l] += 1
        
for i in range(n):
    print(ans[k][i], end=" ")

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate


def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for _ in range(operations):
        temp = [0] * (number + 1)
        for i, v in enumerate(dists):
            left = max(i - v, 0)
            right = min(i + v + 1, number)
            temp[left] += 1
            temp[right] -= 1
        templi = accumulate(temp)
        if templi == dists:
            break
        else:
            dists = templi
    for _ in range(number):
        print(next(dists))


if __name__ == '__main__':
    main()

# Pypy 3 なら通る。Python 3 では無理。

Submission status: Time Limit Exceeded

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

for k in range(K):
    for i in range(N):
        d = A[i]

        l = i - d

        if l < 0:
            l = 0

        r = min(i + d + 1, N)
        for j in range(l, r):
            B[j] += 1

    A = B
    B = [0] * N

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

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()

    for _ in range(k):
        imos = [0 for _ in range(n)]

        for i, ai in enumerate(a):
            imos[max(0, i - ai)] += 1
            if i + ai + 1 < n:
                imos[i + ai + 1] -= 1

        val = 0
        for i, im in enumerate(imos):
            val += im
            a[i] = min(val, n)

        if min(a) == n:
            break

    print(*a, sep=" ")


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate


def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for ope_count in range(operations):
        temp = [0] * (number + 1)
        for i, v in enumerate(dists):
            left = max(i - v, 0)
            right = min(i + v + 1, number)
            temp[left] += 1
            temp[right] -= 1
        templi = list(accumulate(temp))
        if templi == dists:
            dists = templi
            break
        else:
            dists = templi

    print(*list(dists)[:-1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def conv(A,N):
    #A(座標iの電灯の強さリスト)からB(座標iを照らしている電灯数)への変換
    #累積和を使う
    B_=[0 for n in range(N)]
    for n in range(1,N+1):
        il_min=max(n-A[n-1],1)
        il_max=min(n+A[n-1],N)
        B_[il_min-1]+=1
        if il_max<=N-1:
            B_[il_max]-=1

    B=[0 for n in range(N)]
    B[0]=B_[0]
    for n in range(1,N):
        B[n]=B[n-1]+B_[n]
    return B

def main():
    #input
    N,K=map(int,input().strip().split())
    A=list(map(int,input().strip().split()))
    
    if K>45:
        return " ".join(map(str,[N for n in range(N)]))
    else:
        for k in range(K):
            B=conv(A,N)
            if A==B:
                break
            else:
                A=B
        return " ".join(list(map(str,A)))

if __name__=="__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()

    for _ in range(k):
        imos = [0 for _ in range(n)]

        for i, ai in enumerate(a):
            imos[max(0, i - ai)] += 1
            if i + ai + 1 < n:
                imos[i + ai + 1] -= 1

        val = 0
        for i, im in enumerate(imos):
            val += im
            a[i] = min(val, n)

        if min(a) == n:
            break

    print(*a, sep=" ")


if __name__ == '__main__':
    main()