Problem:


Score : 500 points

Problem Statement

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

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

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

Find the intensity of each bulb after the K operations.

Constraints

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

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

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

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

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

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2 

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

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3 



Sample input:
5 1
1 0 0 1 0


Sample output:
1 2 2 1 2

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
  l = [0 for i in range(n)]
  r = [0 for i in range(n)]
  for i in range(n):
    l[max(0, i-a[i])] += 1
    r[min(i+a[i], n-1)] += 1
    
  lighted = 0
  for i in range(n):
    lighted += l[i]
    a[i] = lighted
    lighted -= r[i]
  if len(set(a)) == 1 and a[0] == n:
    break
print(' '.join(list(map(str, a))))

Submission status: Time Limit Exceeded

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


import sys

if K > N**(1/2):
    A = [N]*N
    print(' '.join(map(str, A)))
    sys.exit()
    

import numpy as np
A = np.array(A, dtype=int)
lenA = len(A)
for i in range(K):
    B = np.zeros(lenA, dtype=int)
#    print(B)
    for j in range(lenA):
        num = A[j]
#        print(j, num)
        B[max(0, j - num): min(lenA, j + num + 1)] += 1
#        print(j, B)
    if np.all(A == B):
#        print('same')
        break
    else:
        A = B
#print(i+1)
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import copy
n, k = (int(i) for i in input().split(' '))
a = [int(i) for i in input().split(' ')]

for i in range(k):
    b = [0] * n
    for j in range(1, n + 1):
        b = [b[l - 1] + 1 if j - a[j - 1] <= l and l <= j + a[j - 1] else b[l - 1] for l in range(1, n + 1)]
    a = copy.copy(b)
        
print(' '.join([str(i) for i in a]))

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
ls = list(map(int,input().split()))
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
for p in ls:
    print(p,end=" ")

Submission status: Time Limit Exceeded

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

ptr = 0
buf = [[a for a in an], [0] * len(an)]
#print(an)
for i in range(k):
    ib = buf[ptr]
    buf[ptr ^ 1] = [0] * len(an)
    ob = buf[ptr ^ 1]
    
    for j in range(n):
        s = ib[j]

        lb = max(j - s, 0)
        ub = min(j + s, len(an) - 1)
        for k_ in range(lb, ub + 1):
            ob[k_] += 1
    #print('k =', i + 1)
    #print(ob)
    ptr ^= 1
    if all(a == n for a in ob):
        #print('done!')
        break

print(' '.join(map(str, buf[ptr])))

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):
    B=[0]*N
    for i in range(N):
        if i-A[i]<=0 and i+A[i]>=N:
            p=0
            q=N-1
        elif i-A[i]<=0:
            p=0
            q=i+A[i]
        elif i+A[i]>=N:
            p=i-A[i]
            q=N-1
        else:
            p=i-A[i]
            q=i+A[i]
        for j in range(p,q+1):
            B[j] += 1
        #print(p,q,A[i],i-A[i],i+A[i],A,B)
    A=copy.copy(B)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
def im(a):
    imos = [0] * (3*N+1)
    for i in range(N):
        imos[N+i-min(N,a[i])] += 1
        imos[N+i+min(N,a[i])+1] -= 1
    cs = [0]
    for i in range(1,2*N+1):
        cs.append(cs[i-1]+imos[i-1])
    return cs[N+1:]

N,K,*A = map(int, open(0).read().split())
for i in range(K):
    A = im(A)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

def main():
    N,K = LI()[:]
    A = LI()
    #print(N,K)
    #print(A)

    for _ in range(K):
        B = [0]*N
        for i, a in enumerate(A):
            #print(i, a)
            if a == 0:
                B[i] += 1
            else:
                # i-(a+0.5) ~ i+(a+0.5)
                # i: 整数、a: ＋整数　なので +0.5 は切り捨てられる。
                #　影響範囲は、 i-a ~ i+a
                for p in range(i-a,i+a+1):
                    #print("p:",p)
                    if p >=0 and p < N:
                        B[p] += 1
                #print(B)
        A = B

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(k):
    tmp = [0] * n
    for j in range(n):
        for k in range(a[j]*2+1):
            if (j - a[j] + k) >= 0 and (j - a[j] + k) < n:
                tmp[(j - a[j] + k)] += 1
    a = tmp

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


# 10 5
# 20 8
# 40 10
# 80 12
# 160 15

Submission status: Time Limit Exceeded

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

for i in range(k):
  b = [ 0 for bi in range(n) ]
  for j in range(n):
    b[j] += 1
    for bb in range(a[j]):
      if  j + bb + 1 < n :
        b[j + bb + 1] += 1
      if  j - bb - 1 >= 0 :
        b[j - bb - 1] += 1
  a = [ ai for ai in b ]
print(b[0],end="")
for i in b[1:]:
  print(" {}".format(i),end="")
print()

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
import math
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


def main():
    N,K = isRaw()
    As = isRaw()
    for k in range(K):
        #nAs = [0]*N
        dh = []
        for aidx,a in enumerate(As):
            heappush(dh, (max(0, aidx-a),1))
            heappush(dh, (min(aidx+a+1, N),-1))
        d = 0
        for x in range(N):
            while x ==dh[0][0]:
                c, q = heappop(dh)
                d+=q
            As[x] = d

        
        if sum(As) == N*N:
            break
        
    print(" ".join([str(a) for a in As]))


main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 13 21:06:06 2020

@author: matanoakihiro
"""


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

sousa=0

while sousa<K:
    for i in range(N):
        ma=i+A[i]+1
        if ma>N:
            ma=N
        mi=i-A[i]
        if mi<0:
            mi=0
        for j in range(mi,ma):
            B[j]+=1
    A=list(B)
    B=[0]*N
    sousa+=1

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

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

for _ 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
    
    a = b

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K >= 200:
    print(*[N]*N)
    exit()
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
    if A == [N]*N:
        break
print(*A)

Submission status: Time Limit Exceeded

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

for k in range(K):
    counterlist = np.array([0]*N)
    for i in range(N):
        d = A[i]
        u = max(0,i-d)
        v = min(N-1,i+d)
        counterlist[u:v+1]+=1
    if all(A==counterlist):
        print(*A)
        break
    A = counterlist
    
        

else:
    print(*A)

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy

def I(): return int(sys.stdin.readline().rstrip())
def LI():return list(map(int,sys.stdin.readline().rstrip().split()))
def LS():return list(sys.stdin.readline().rstrip().split())

def main():
    N,K = LI()[:]
    A = LI()
    #print(N,K)
    #print(A)

    for _ in range(K):
        B = [0]*N
        for i, a in enumerate(A):
            #print(i, a)
            if a == 0:
                B[i] += 1
            else:
                # i-(a+0.5) ~ i+(a+0.5)
                # i: 整数、a: ＋整数　なので +0.5 は切り捨てられる。
                #　影響範囲は、 i-a ~ i+a
                for p in range(i-a,i+a+1):
                    #print("p:",p)
                    if p >=0 and p < N:
                        B[p] += 1
                #print(B)
        A = copy.deepcopy(B)

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))  # 整数のリスト

    next_A = [0 for _ in range(N)]

    for _ in range(K):
        for i in range(N):
            for j in range(i-A[i], i+A[i]+1):
                if j >= 0 and j < N:
                    next_A[j] += 1
        A = next_A
        next_A = [0 for _ in range(N)]

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

if __name__ == '__main__':
    main()

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()))
    A_temp=[0]*N
    for k in range(K):
        for i in range(N):
            for j in range(max(0,i-A[i]),min(N,i+A[i]+1)):
                A_temp[j]+=1
        A=A_temp
        A_temp=[0]*N
    print(' '.join(map(str,A)))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = map(int,S().split())
A = LI()

from itertools import accumulate

ANS = A+[0]

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

del ANS[N]
print(*ANS)

Submission status: Time Limit Exceeded

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


for n in range(K):
    li = [0 for i in range(N)]
    for i,x in enumerate(Bi):
        li[i] += 1
        for l in range(1,x+1):
            if i - l >= 0:
                li[i-l] += 1
            if i + l <= N - 1:
                li[i+l] += 1
    Bi = li
for i in li:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for k in range(K):
    wa = np.zeros(N)
    for i in range(N):
        lights = np.zeros(N)
        lights[max(0, i-A[i]):min(N, i+1+A[i])] = 1
        wa = wa + lights
    A = list(map(int, wa))
print(' '.join(map(str, A)))

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n, k = i_map()
    num_list = i_list()

    ans_list = [0] * n

    for i in range(k):
        if i % 2 != 0:
            if ans_list.count(n) == n:
                print(*ans_list)
                exit()
            num_list = [0] *n  
            for j in range(n):
                for w in range(ans_list[j]+1):
                    if w == 0:
                        num_list[j] += 1
                    else:
                        if j + w < n:
                            num_list[j+w] += 1
                        if j - w >= 0:
                            num_list[j-w] += 1
        else:
            if num_list.count(n) == n:
                print(*num_list)
                exit()
            ans_list = [0] *n  
            for j in range(n):
                for w in range(num_list[j]+1):
                    if w == 0:
                        ans_list[j] += 1
                    else:
                        if j + w < n:
                            ans_list[j+w] += 1
                        if j - w >= 0:
                            ans_list[j-w] += 1

    if k % 2 == 0:
        print(*num_list)
    else:
        print(*ans_list)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, k = (int(v) for v in input().split(" "))
l = [int(v) for v in input().split(" ")]
cnt = len(l)
for _ in range(k):
    next_l = [0] * cnt
    for i, v in enumerate(l):
        from_idx = max(i - v, 0)
        to_idx = min(i + v, cnt - 1)
        for j in range(from_idx, to_idx+1):
            next_l[j] = next_l[j] + 1
    l = next_l

print(" ".join([str(i) for i in l]))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
if K >= 1000:
    print(*[N]*N)
    exit()
for i in range(K):
    newA = [0]*N
    for j in range(N):
        newA[max(0,j-A[j])] += 1
        if j+A[j]+1 < N:
            newA[min(N-1,j+A[j]+1)] -= 1
    A = list(itertools.accumulate(newA))
    if A == [N]*N:
        break
print(*A)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
A=[*map(int,input().split())]
# print(n,k)
# print(A)
B = []
for i in range(k):
    B = [0]*n
    for j in range(n):
        d = A[j] # 強さ
        x = j + 1
        l = max(1, abs(x-d)) # 範囲
        r = min(n, abs(x+d)) # 範囲
        # print('x,l,r',x,l,r)
        for k in range(l-1,r): # (l,r)
            B[k] += 1
        # print('---')
    # print(B)
    A = B

print(*A, sep=' ')

Submission status: Time Limit Exceeded

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

for i in range(k):
  for j in range(n):
    for k in range(n):
      if a[k] >= abs(k-j):
        b[j] += 1
  a = b  
  b = [0]*n
  if a[0] == n:
    count += 1
  if count ==2 :
    break
  else:
    continue
  break
    
print(*a)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,K = map(int,input().split())
a = list(map(int,input().split()))

for k in range(K):
    light = [0]*n
    st = [0]*n

    for i in range(n):
        if i - a[i] >= 0:
            light[i-a[i]] += 1
        else:
            light[0] += 1
        
        if i + a[i] + 1 <= n-1:
            light[i + a[i] + 1] -= 1

    st[0] = light[0]
    for i in range(1,n):
        st[i] = st[i-1] + light[i]    
    
    if st == a:
        for ans in st:
            print(ans, end = " ")
    
    a = st[::]
for ans in a:
    print(ans, end = " ")

Submission status: Time Limit Exceeded

Solution code:
import math

def pulse_num(n):
    return n + 1
if __name__ == "__main__":
    N, K= list(map(int, input().split()))
    A = list(map(int, input().split()))
    for k in range(K):
        B = [1] * len(A)
        for i in range(N):
            if A[i] != 0:
                if i - A[i] - 0.5 < 0:
                    low = 0
                else:
                    low = math.ceil(i - A[i] - 0.5)
                if i + A[i] + 0.5 > N - 1:
                    high = N - 1
                else:
                    high = math.floor(i + A[i] + 0.5)
                B[low:high+1] = list(map(pulse_num, B[low:high+1]))
                B[i] -= 1
        A = B

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def count_num_light(a):
  ret = np.array([0 for _ in range(len(a))])
  for i in range(len(a)):
    start = max(0, i-a[i])
    ret[start:i+a[i]+1] += 1
  
  return ret
                  
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
num_light = count_num_light(a)

for i in range(k-1):
  num_light = count_num_light(num_light)
  if np.sum(num_light) == n**2:
    break

print(*num_light)

Submission status: Time Limit Exceeded

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

    for _ in range(k):
        num = [0]*n
        for _2 in range(n):
            min = _2 - a[_2] if 0 < _2 - a[_2] - 0.5 else 0
            max = _2 + a[_2] if n > _2 + a[_2] + 0.5 else n-1
            for _3 in range(min, max+1):
                num[_3] += 1
        if a[0]==n and all(a):
            break


        a = num

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

Submission status: Time Limit Exceeded

Solution code:
"""N個の電球　操作K回"""
N, K = map(int, input().split())

arr = list(map(int, input().split()))
count = 0

for _ in range(K):
    next = [0]*N
    for i in range(N):
        for j in range(i-arr[i],i+arr[i]+1,1):
            if 0<=j<=N-1:
                next[j] +=1
    arr = next
    count += 1
    if arr == [N]*N:
        for kk in range(N):
            arr[kk] += K-count
        print(*arr)
        exit()

print(*arr)

Submission status: Time Limit Exceeded

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

    def light_range(A):
        lighted = [0 for _ in range(N)]
        for i, a in enumerate(A):
            for j in range(max(0, i-a), min(N, i+a+1)):
                lighted[j] += 1
        return lighted
    
    lighted = light_range(A)

    def handle():
        nonlocal A, lighted
        for i, lighter in enumerate(lighted):
            A[i] = lighted[i]
        lighted = light_range(A)

    for _ in range(K):
        handle()
    
    print(" ".join(map(str, A)))



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#C
N,K = map(int, input().split())
lights = list(map(int, input().split()))
#print(lights)
bright = [0 for i in range(N)]
#print(bright)
for kaisuu in range(K):
    #すべての電球の明るさがNになったら終わる
    if sum(lights) == N**2:
        break
    for i in range(N):
        #左の電球から順に、その電球が照らす範囲のbrightに+1
        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)
#print(lights)
for ans in lights:
    print(ans, end=" ")

Submission status: Time Limit Exceeded

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

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

for _ in range(K):
    B = [0]*N
    for i, a in enumerate(A):
        bottom = i - a
        top = i + a + 1
        if bottom < 0:
            bottom = 0
        if top > N:
            top = N
        B[bottom:top] = list(map(lambda x: x+1, B[bottom:top]))
    A = B[:]

ans = ' '.join(list(map(str, A)))
print(ans)

Submission status: Time Limit Exceeded

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


def p(current_a):
    global N

    power = [1 for i in range(N)]
    for i, a in enumerate(current_a):
        if a == 0:
            continue
        for x in range(1, a + 1):
            if i - x >= 0:
                power[i-x] += 1
            if i + x < N:
                power[i+x] += 1
    return power

for _ in range(K):
    A = p(A)

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

Submission status: Time Limit Exceeded

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

import math
import numpy as np


for i in range(K):
  count_list = [0] * N
  #何個光ってるか
  for j in range(N):
    count_list_sub = [0] * N
    first = math.floor(j+1 - A_list[j] - 0.5)+1
    last = math.floor(j+1 + A_list[j] + 0.5)
    if(first<1):
      first = 1
    if(last<1):
      last = 1
    if(first>N):
      first = N
    if(last>N):
      last = N
    count_list_sub[first-1:last]=[1]*((last)-(first-1))
    count_list = np.array(count_list_sub) + np.array(count_list)
  A_list = count_list
  
A_list=[str(a) for a in A_list]
A_list=' '.join(A_list)
print(A_list)

Submission status: Time Limit Exceeded

Solution code:
def adjust_light(arr):
    counter = []
    for idx in range(0, len(arr)):
        counter.append(0)
    
    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
        reach_points = range(min, max+1)
        for point in reach_points:
            counter[point] = counter[point] + 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 = list(map(int,input().split()))
A = list(map(int,input().split()))
for k in range(K):
    B = [0 for i in A]
    for i in range(N):
        C = []
        for d in range(A[i]+1):
            if i+d <= N-1:
                C.append(i + d)
            if i-d >= 0:
                C.append(i - d)
        C = list(set(C))
        for c in C:
            B[c] += 1
    A = [b for b in B]
    if A == [N for l in range(N)]:
        break
B = [str(b) for b in B]
print(' '.join(B))

Submission status: Time Limit Exceeded

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

if k > (n // 2):
    for j in range(n):
        a[j] = n;
        
else:
    for i in range(k):
        b = [0] * n;
    
        for p in range(n):
            for q in range(max(p-a[p],0),min(p+a[p]+1,n)):
                b[q] += 1;
                
        for v in range(n):
            a[v] = b[v];
        
        if a.count(n) == n:
            break;
        

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

Submission status: Time Limit Exceeded

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

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

    for i in range(1,k+1):
        fin = 0
        for j in range(n):
            pwr = dp[i-1][j]
            if pwr >= max(j,n-1-j) :
                fin+=1
                continue
            for a in range(max(j-pwr,0),min(j+pwr+1,n)):
                dp[i][a]+=1

        if fin == n:
            break
        else:
            for j in range(n):
                dp[i][j] += fin
    
    if fin == n:
        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:
import numpy as np

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



for j in range(K):
    Alight=np.array([0]*N)
    for i in range(N):
        fro=i-A[i]
        to=i+A[i]+1
        if fro < 0:
            fro=0
        #for k in range(fro,to):
        Alight[fro:to]+=1
        #print(fro)
        #print(to)
    #print(Alight)
    A=Alight[:]
    if 2**(j-2) > N:
        break

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

for _ in range(K):
    result = np.array([0]*N)
    for i in range(N):
        _idx_st = i - A[i]
        idx_st = 0 if _idx_st < 0 else _idx_st
        _idx_end = i + A[i]
        idx_end = N if i + A[i] >= N else _idx_end + 1

        result[idx_st:idx_end]+=1
    A=result
print(*result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array(lr() + [0])
# ある回数から先は全ての電球にNを足す
for _ in range(min(K, 10 ** 2)):
    next = np.array([0] * (N+1))
    for i in range(N):
        x = A[i]
        next[max(0, i-x)] += 1
        next[min(N-1, i+x)+1] -= 1
    A = next.cumsum()

print(*A[:-1])

Submission status: Time Limit Exceeded

Solution code:
import math
n , k = map(int, input().split())
a = list(map(int,input().split()))
a1=[0]*(n+1)
k = min(k,int(math.log2(n)*2.5))
for i in range(k):
    for j in range(n):
        st=j-a[j]
        gl=j+a[j]
        if st<0:
            st=0
        if gl>=n:
            gl=n-1
        a1[st]+=1
        a1[gl+1]-=1
    for k in range(1,n):
        a1[k]=a1[k-1]+a1[k]
    a=a1[:n]
    a1=[0]*(n+1)
print(' '.join([str(n) for n in a]))

Submission status: Time Limit Exceeded

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

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

for _ in range(K):
    events = [[] for _ in range(N*2+2)]
    for i, a in enumerate(As):
        l = 2*(i-a)-1
        r = 2*(i+a)+1
        events[-1 if l < -1 else l].append(i)
        events[N*2 if r > N*2 else r].append(i)
    active = set()
    L = 0
    nextAs = []
    for i in range(N):
        for k in events[2*i-1]:
            if k in active:
                active.remove(k)
                L -= 1
            else:
                active.add(k)
                L += 1
        nextAs.append(L)
    As = nextAs

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

Submission status: Time Limit Exceeded

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

for k in range(K):
    newLight = [0] * N
    for i in range(N):
        light = d[k][i]
        if light > 0:
            for j in range(2 * light + 1):
                if j != light:
                    loc = i - light + j
                    if loc >= 0 and loc < N:
                       newLight[loc] += 1
    newLight = list(map(lambda x : x + 1, newLight))
    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:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(k):
  tmp = [0] * n
  for j in range(n):
    left = j-a[j] if j-a[j] >= 0 else 0
    right = j+a[j] if j+a[j] <= n-1 else n-1
    for l in range(left, right+1):
      tmp[l] += 1
  a = tmp
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

if K > N - 1:
    A = [N] * N
else:
    for i in range(K):
        for j,num in enumerate(A):
            for k in range(max(j-num, 0), min(j+num, N-1) + 1):
                B[k] += 1
        A, B = B.copy(), [0] * N

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

def imo(a):
    imos=[0]*(n+1)

    for i in range(n):
        imos[max(0,i-a[i])]+=1
        imos[min(n,i+a[i]+1)]-=1
    
    arr=np.array(imos)
    cums=np.cumsum(arr)

    return cums[:n].tolist()

for i in range(k):
    a=imo(a)
    
print(*a)

Submission status: Time Limit Exceeded

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

import math
import numpy as np


for i in range(K):
  count_list = [0] * N
  
  #何個光ってるか
  for j in range(N):
    count_list_sub = [0] * N
    first = math.floor(j+1 - A_list[j] - 0.5)+1
    last = math.floor(j+1 + A_list[j] + 0.5)
    if(first<1):
      first = 1
    if(last<1):
      last = 1
    if(first>N):
      first = N
    if(last>N):
      last = N
    #for k in range(first-1,last):
      #count_list[k] = count_list[k]+1
    count_list_sub[first-1:last]=[1]*((last)-(first-1))
    a = np.array(count_list_sub) + np.array(count_list)
    count_list = list(a)
    #print(count_list)
  A_list = count_list
  
A_list=[str(a) for a in A_list]
A_list=' '.join(A_list)
print(A_list)